]> granicus.if.org Git - clang/commitdiff
fix PR7943, a corner case with the GNU __VA_ARGS__ comma
authorChris Lattner <sabre@nondot.org>
Sat, 21 Aug 2010 00:27:00 +0000 (00:27 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Aug 2010 00:27:00 +0000 (00:27 +0000)
swallowing extension.

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

lib/Lex/TokenLexer.cpp
test/Preprocessor/macro_fn_comma_swallow.c

index 49dc016590ab96e738b0f61a851f06e3e5fe80eb..94719b0baa3c7272a5cc049a01cb388a823f56d9 100644 (file)
@@ -268,6 +268,13 @@ void TokenLexer::ExpandFunctionArguments() {
       // Remove the paste operator, report use of the extension.
       PP.Diag(ResultToks.back().getLocation(), diag::ext_paste_comma);
       ResultToks.pop_back();
+      
+      // If the comma was right after another paste (e.g. "X##,##__VA_ARGS__"),
+      // then removal of the comma should produce a placemarker token (in C99
+      // terms) which we model by popping off the previous ##, giving us a plain
+      // "X" when __VA_ARGS__ is empty.
+      if (!ResultToks.empty() && ResultToks.back().is(tok::hashhash))
+        ResultToks.pop_back();
     }
     continue;
   }
index 57425910b8a9eff8fd8208c6e807bab16adc8793..fd32c84765f71ee93af652ccb8e53ef603d5043e 100644 (file)
@@ -19,3 +19,8 @@ X3(foo)
 // PR3880
 #define X4(...)  AA , ## __VA_ARGS__ BB
 X4()
+
+// RUN: %clang_cc1 %s -E | grep '5: 1'
+// PR7943
+#define X5(x,...) x##,##__VA_ARGS__
+5: X5(1)