summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp6
-rw-r--r--clang/test/Preprocessor/macro_fn_comma_swallow.c5
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 6ec306196db..f1c69d99341 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -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);
diff --git a/clang/test/Preprocessor/macro_fn_comma_swallow.c b/clang/test/Preprocessor/macro_fn_comma_swallow.c
index 4e06f89a160..e985138a5c4 100644
--- a/clang/test/Preprocessor/macro_fn_comma_swallow.c
+++ b/clang/test/Preprocessor/macro_fn_comma_swallow.c
@@ -14,3 +14,8 @@ X2()
X3(foo)
+
+// RUN: clang-cc %s -E | grep 'AA BB'
+// PR3880
+#define X4(...) AA , ## __VA_ARGS__ BB
+X4()
OpenPOWER on IntegriCloud