[cfe-dev] Premature macro expansion in preprocessor?
Andy Gibbs
andyg1001 at hotmail.co.uk
Fri Nov 9 14:37:22 PST 2012
Hi,
In going through the preprocessor code in clang, I have noted a tendancy
towards using Lex(Tok) over LexUnexpandedToken(Tok), for example in the
built-in macro implementations.
This means, the following "works":
#define HB __has_builtin
#define LP (
#define BT __builtin_trap
#define RP )
HB LP BT RP // expands to 1
My question is, is this intentional, or an oversight? Is it worth my while
going through and changing Lex(...) to LexUnexpandedToken(...) in these
cases? Normally, preprocessor rules require an extra level of expansion, as
in:
#define EXPAND(...) __VA_ARGS__
#define MACRO(A) String: #A
#define M MACRO
#define S test
M LP S RP // expands to MACRO ( test )
EXPAND(M LP S RP) // expands to String: "test"
Thoughts?
Andy
More information about the cfe-dev
mailing list