Closed
Labels
Description
Preprocessing of this code with simplecpp:
#define CAT(a, b) CAT2(a, b)
#define CAT2(a, b) a ## b
#define FOO x
#define BAR() CAT(F, OO)
#define BAZ CAT(B, AR)()
BAZproduces this result:
CAT ( F , OO )
All mainstream preprocessors (GCC, Clang, MSVC) produce this result (https://godbolt.org/z/9GhhTarE3):
x
It seems that simplecpp decides to not expand CAT a second time during evaluation of BAZ. I don't know if this is correct from the point of view of the standard.
Some additional observations:
- If the last line is replaced with
CAT(B, AR)()then all preprocessors produce the same result:x. - If
BAR()is converted from function-like macro to regular macro:then all preprocessors produce the same result:#define BAR CAT(F, OO) #define BAZ CAT(B, AR)
CAT ( F , OO ).
Reacted by SherAndrei
Activity
mgood7123 commentedon Jan 20, 2022
I don't know if this is correct from the point of view of the standard.it is notfirewave commentedon Jul 3, 2025
test.cpp: added test for cppcheck-opensource#231 [skip ci]
test.cpp: added test for cppcheck-opensource#231
test.cpp: added tests for cppcheck-opensource#40
test.cpp: added test for cppcheck-opensource#231