]> granicus.if.org Git - clang/commitdiff
fix PR3880, fixing a comma swallowing bug handling macros that only take
authorChris Lattner <sabre@nondot.org>
Wed, 25 Mar 2009 21:08:24 +0000 (21:08 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 25 Mar 2009 21:08:24 +0000 (21:08 +0000)
... arguments.

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

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

index 6ec306196db0d62240c7c38d4551c1253b744167..f1c69d9934158c8f9992fa2440578eff87a94505 100644 (file)
@@ -403,6 +403,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
     Tok.setLocation(EndLoc);
     Tok.setLength(0);
     ArgTokens.push_back(Tok);
+  } else if (NumActuals == 1 && ArgTokens.size() == 1) {
+    // If there is exactly one argument, and that argument is just an EOF token,
+    // then we have an empty "()" argument empty list.  This is fine, even if
+    // the macro expects one argument (the argument is just empty).  However, if
+    // the macro expects "...", then we need to know that it was elided.
+    isVarargsElided = MinArgsExpected == 1 && MI->isVariadic();
   }
   
   return MacroArgs::create(MI, &ArgTokens[0], ArgTokens.size(),isVarargsElided);
index 4e06f89a160feca929d7b63aaad06c1ac67d6658..e985138a5c44c27d8398e78937197400827061a2 100644 (file)
@@ -14,3 +14,8 @@ X2()
 X3(foo)
 
 
+
+// RUN: clang-cc %s -E | grep 'AA BB'
+// PR3880
+#define X4(...)  AA , ## __VA_ARGS__ BB
+X4()