aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-05-08 05:10:33 +0000
committerChris Lattner <sabre@nondot.org>2008-05-08 05:10:33 +0000
commit63bc0358706e63faf705803c4799e073b91a63f0 (patch)
tree105048c54ef4c557d62bcdfaef8e2e218d5e701d
parentb6403af3e697f90308fe8daf82f7b15252d198bc (diff)
The awesome GNU "comma elision extension" works with both the standard
__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
-rw-r--r--lib/Lex/PPMacroExpansion.cpp9
-rw-r--r--test/Preprocessor/macro_fn_varargs_named.c3
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index 23dfbbca57..fb9b613f5c 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -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()
diff --git a/test/Preprocessor/macro_fn_varargs_named.c b/test/Preprocessor/macro_fn_varargs_named.c
index 75ee96105d..095de82bbb 100644
--- a/test/Preprocessor/macro_fn_varargs_named.c
+++ b/test/Preprocessor/macro_fn_varargs_named.c
@@ -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)