aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-22 21:41:40 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-22 21:41:40 +0000
commited5d651b0d4b99d0b68bb8d4633e49b98c95bd8f (patch)
treef59bfc4080cd48710143db1d396c311581e1deb0 /lib/Parse/ParseDecl.cpp
parentcf54959eae25fb3050f41833f0eab91042fb1269 (diff)
In C++, a variadic function does not need an ellipsis prior to the comma. Parse it in both C and C++, but diagnose it as an error in C with a fix-it hint to add the comma.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82576 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDecl.cpp')
-rw-r--r--lib/Parse/ParseDecl.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 4ca5b48e8b..75ff82772a 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -2448,6 +2448,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
/// parameter-type-list: [C99 6.7.5]
/// parameter-list
/// parameter-list ',' '...'
+/// [C++] parameter-list '...'
///
/// parameter-list: [C99 6.7.5]
/// parameter-declaration
@@ -2647,7 +2648,21 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
}
// If the next token is a comma, consume it and keep reading arguments.
- if (Tok.isNot(tok::comma)) break;
+ if (Tok.isNot(tok::comma)) {
+ if (Tok.is(tok::ellipsis)) {
+ IsVariadic = true;
+ EllipsisLoc = ConsumeToken(); // Consume the ellipsis.
+
+ if (!getLang().CPlusPlus) {
+ // We have ellipsis without a preceding ',', which is ill-formed
+ // in C. Complain and provide the fix.
+ Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
+ << CodeModificationHint::CreateInsertion(EllipsisLoc, ", ");
+ }
+ }
+
+ break;
+ }
// Consume the comma.
ConsumeToken();