]> granicus.if.org Git - clang/commitdiff
The awesome GNU "comma elision extension" works with both the standard
authorChris Lattner <sabre@nondot.org>
Thu, 8 May 2008 05:10:33 +0000 (05:10 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 May 2008 05:10:33 +0000 (05:10 +0000)
__VA_ARGS__ syntax as well as with the amazingly awesome GNU "named
variadic macro" extension.  Allow it with the GNU syntax as well.

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

lib/Lex/PPMacroExpansion.cpp
test/Preprocessor/macro_fn_varargs_named.c

index 23dfbbca578f6b17a9ec2abbd6ccd4c60b004123..fb9b613f5c8e7f0b528042791f0a83185e60bc2b 100644 (file)
@@ -370,9 +370,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
       // A("blah")
       Diag(Tok, diag::ext_missing_varargs_arg);
 
-      // Remember this occurred if this is a C99 macro invocation with at least
-      // one actual argument.
-      isVarargsElided = MI->isC99Varargs() && MI->getNumArgs() > 1;
+      // Remember this occurred if this is a macro invocation with at least
+      // one actual argument.  This allows us to elide the comma when used for
+      // cases like:
+      //   #define A(x, foo...) blah(a, ## foo) 
+      //   #define A(x, ...) blah(a, ## __VA_ARGS__) 
+      isVarargsElided = MI->getNumArgs() > 1;
     } else if (MI->getNumArgs() == 1) {
       // #define A(x)
       //   A()
index 75ee96105d8bdb644cb8b0e5d4734783c33fd406..095de82bbb709f64a914de5fe8c4012925b706d3 100644 (file)
@@ -1,7 +1,10 @@
 // RUN: clang -E %s | grep '^a: x$' &&
 // RUN: clang -E %s | grep '^b: x y, z,h$'
+// RUN: clang -E %s | grep '^c: foo(x)$'
 
 #define A(b, c...) b c
 a: A(x)
 b: A(x, y, z,h)
 
+#define B(b, c...) foo(b, ## c)
+c: B(x)