forked from OSchip/llvm-project
Lex: Require that '#' be followed by a macro parameter name when preceded by '##'
After lexing a '##', we would look ahead and check to see if it was followed by '__VA_ARGS__'. After doing so, we would then go ahead and lex the token. However we would fail in the case where the '##' was followed by a '#' followed by an identifier because we would have lexed the '#' separately from the identifier, bypassing our parameter validation logic. Instead, lex the tokens coming after the '##' later. This fixes PR17804. llvm-svn: 194059
This commit is contained in:
parent
04a0e5050f
commit
76faf1f525
|
@ -2005,13 +2005,8 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
|
||||||
MI->getReplacementToken(NumTokens-1).is(tok::comma))
|
MI->getReplacementToken(NumTokens-1).is(tok::comma))
|
||||||
MI->setHasCommaPasting();
|
MI->setHasCommaPasting();
|
||||||
|
|
||||||
// Things look ok, add the '##' and param name tokens to the macro.
|
// Things look ok, add the '##' token to the macro.
|
||||||
MI->AddTokenToBody(LastTok);
|
MI->AddTokenToBody(LastTok);
|
||||||
MI->AddTokenToBody(Tok);
|
|
||||||
LastTok = Tok;
|
|
||||||
|
|
||||||
// Get the next token of the macro.
|
|
||||||
LexUnexpandedToken(Tok);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,3 +32,5 @@ XX // expected-error {{attempt to use a poisoned identifier}}
|
||||||
#define VA __VA_ ## ARGS__
|
#define VA __VA_ ## ARGS__
|
||||||
int VA; // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
|
int VA; // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
|
||||||
|
|
||||||
|
#define LOG_ON_ERROR(lvl) ::X x## #__LINE__; // expected-error {{'#' is not followed by a macro parameter}}
|
||||||
|
LOG_ON_ERROR(0);
|
||||||
|
|
Loading…
Reference in New Issue