aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-20 21:08:10 +0000
committerChris Lattner <sabre@nondot.org>2009-04-20 21:08:10 +0000
commit97e2de171de555feb1ef422e71874082a67498c9 (patch)
tree497ca594ae45cac19e34c528a83315330af4cd8b /lib/Lex
parent3251ceb90b3fec68e86d6dcfa58836e20a7205c3 (diff)
fix the second half of PR4006 and rdar://6807000 by treating
() as being either zero arguments or one empty argument depending on situation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69627 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex')
-rw-r--r--lib/Lex/PPMacroExpansion.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index 330e2a17aa..48c166daba 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -392,7 +392,16 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
if (NumActuals < MinArgsExpected) {
// There are several cases where too few arguments is ok, handle them now.
- if (NumActuals+1 == MinArgsExpected && MI->isVariadic()) {
+ if (NumActuals == 0 && MinArgsExpected == 1) {
+ // #define A(X) or #define A(...) ---> A()
+
+ // If there is exactly one argument, and that argument is missing,
+ // then we have an empty "()" argument empty list. This is fine, even if
+ // the macro expects one argument (the argument is just empty).
+ isVarargsElided = MI->isVariadic();
+ } else if (MI->isVariadic() &&
+ (NumActuals+1 == MinArgsExpected || // A(x, ...) -> A(X)
+ (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...) -> A()
// Varargs where the named vararg parameter is missing: ok as extension.
// #define A(x, ...)
// A("blah")
@@ -404,12 +413,7 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
// #define B(x, ...) blah(a, ## __VA_ARGS__)
// #define C(...) blah(a, ## __VA_ARGS__)
// A(x) B(x) C()
- isVarargsElided = true; //MI->getNumArgs() > 1;
- } else if (NumActuals == 0 && MinArgsExpected == 1) {
- assert(!MI->isVariadic() && "Variadic should be handled by case above");
- // If there is exactly one argument, and that argument is missing,
- // then we have an empty "()" argument empty list. This is fine, even if
- // the macro expects one argument (the argument is just empty).
+ isVarargsElided = true;
} else {
// Otherwise, emit the error.
Diag(Tok, diag::err_too_few_args_in_macro_invoc);