]> granicus.if.org Git - clang/commitdiff
Lex: Require that '#' be followed by a macro parameter name when preceded by '##'
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 5 Nov 2013 09:30:17 +0000 (09:30 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 5 Nov 2013 09:30:17 +0000 (09:30 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194059 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/macro_paste_bad.c

index a952b2ef1b90676f1643d1d56879e9f19718a66c..9ba65a57a842fa3355a2969c4e753945dfdb9c48 100644 (file)
@@ -2005,13 +2005,8 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
             MI->getReplacementToken(NumTokens-1).is(tok::comma))
           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(Tok);
-        LastTok = Tok;
-
-        // Get the next token of the macro.
-        LexUnexpandedToken(Tok);
         continue;
       }
 
index 0a028a44686e99debcaee69e2f734c7d5db73824..211465433b5e7806a96c7ac8ef95b98b856528ce 100644 (file)
@@ -32,3 +32,5 @@ XX     // expected-error {{attempt to use a poisoned identifier}}
 #define VA __VA_ ## ARGS__
 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);