]> granicus.if.org Git - clang/commitdiff
Fix PR4006, incorrect handling of __VA_ARGS__ when it was the first token
authorChris Lattner <sabre@nondot.org>
Sun, 19 Apr 2009 18:26:34 +0000 (18:26 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Apr 2009 18:26:34 +0000 (18:26 +0000)
in a function-like macro body.  This has the added bonus of moving some
function-like macro specific code out of the object-like macro codepath.

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

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

index e0bd5a1ee0732925ac33927435a10267728f40b3..15477b63d3a6805e48ea0666041098c57e52f95c 100644 (file)
@@ -1306,6 +1306,15 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
       return;
     }
 
+    // If this is a definition of a variadic C99 function-like macro, not using
+    // the GNU named varargs extension, enabled __VA_ARGS__.
+    
+    // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
+    // This gets unpoisoned where it is allowed.
+    assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned!");
+    if (MI->isC99Varargs())
+      Ident__VA_ARGS__->setIsPoisoned(false);
+    
     // Read the first token after the arg list for down below.
     LexUnexpandedToken(Tok);
   } else if (Features.C99) {
@@ -1334,15 +1343,6 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
       Diag(Tok, diag::warn_missing_whitespace_after_macro_name);
   }
   
-  // If this is a definition of a variadic C99 function-like macro, not using
-  // the GNU named varargs extension, enabled __VA_ARGS__.
-  
-  // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
-  // This gets unpoisoned where it is allowed.
-  assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned!");
-  if (MI->isC99Varargs())
-    Ident__VA_ARGS__->setIsPoisoned(false);
-  
   // Read the rest of the macro body.
   if (MI->isObjectLike()) {
     // Object-like macros are very simple, just read their body.
index 8dc8b77d6df77f6b27367fd6167785f56d9dfd77..90dc2f06d68f7e5d72c8c7cacdf4928764c77e92 100644 (file)
@@ -25,3 +25,9 @@ two(
              expected-error {{too many arguments provided to function-like macro invocation}} */
     )     
 two(,)      /* expected-warning 2 {{empty macro arguments were standardized in C99}} */
+
+
+
+/* PR4006 */
+#define e(...) __VA_ARGS__  /* expected-warning {{variadic macros were introduced in C99}} */
+e(x)