r194059 - Lex: Require that '#' be followed by a macro parameter name when preceded by '##'

David Majnemer david.majnemer at gmail.com
Tue Nov 5 01:30:17 PST 2013


Author: majnemer
Date: Tue Nov  5 03:30:17 2013
New Revision: 194059

URL: http://llvm.org/viewvc/llvm-project?rev=194059&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Preprocessor/macro_paste_bad.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=194059&r1=194058&r2=194059&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Nov  5 03:30:17 2013
@@ -2005,13 +2005,8 @@ void Preprocessor::HandleDefineDirective
             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;
       }
 

Modified: cfe/trunk/test/Preprocessor/macro_paste_bad.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_bad.c?rev=194059&r1=194058&r2=194059&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_paste_bad.c (original)
+++ cfe/trunk/test/Preprocessor/macro_paste_bad.c Tue Nov  5 03:30:17 2013
@@ -32,3 +32,5 @@ XX     // expected-error {{attempt to us
 #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);





More information about the cfe-commits mailing list