]> granicus.if.org Git - clang/commitdiff
In C++, a variadic function does not need an ellipsis prior to the comma. Parse it...
authorDouglas Gregor <dgregor@apple.com>
Tue, 22 Sep 2009 21:41:40 +0000 (21:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 22 Sep 2009 21:41:40 +0000 (21:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82576 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/Sema/function.c

index 9a042605bde0b714ff83eec768bbb860304eb67e..c018497907f63b1e6f86ac546720eb1e77d3ce61 100644 (file)
@@ -136,6 +136,8 @@ def err_rvalue_reference : Error<
 def err_argument_required_after_attribute : Error<
   "argument required after attribute">;
 def err_missing_param : Error<"expected parameter declarator">;
+def err_missing_comma_before_ellipsis : Error<
+  "C requires a comma prior to the ellipsis in a variadic function type">;
 def err_unexpected_typedef_ident : Error<
   "unexpected type name %0: expected identifier">;
 def err_expected_class_name : Error<"expected class name">;
index 4ca5b48e8b671b25f5a05e9af2e4a2d2cc0609a2..75ff82772a10b6925141512d858226966a06e84f 100644 (file)
@@ -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();
index c9d8630c47f6ba47921bd5bcf76af30ce29064d7..e7a37f1a2fc125e280bce2750f8b896e366c8dd3 100644 (file)
@@ -87,3 +87,5 @@ unknown_type t19(int* P) {   // expected-error {{unknown type name 'unknown_type
   P = P+1;  // no warning.
 }
 
+// missing ',' before '...'
+void t20(int i...) { } // expected-error {{requires a comma}}