]> granicus.if.org Git - clang/commitdiff
Improve recovery when a comma is missing between enumerators in an
authorDouglas Gregor <dgregor@apple.com>
Tue, 7 Sep 2010 14:51:08 +0000 (14:51 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 7 Sep 2010 14:51:08 +0000 (14:51 +0000)
enumeration definition. Fixes <rdar://problem/7159693>.

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
test/FixIt/fixit.c

index 50e98706f51b525c014c58d804a3d1e0d7c1968a..28cd2d98f07f6e3ba02d4ef731ca614d5bb5a833 100644 (file)
@@ -55,6 +55,8 @@ def ext_c99_compound_literal : Extension<
 def ext_enumerator_list_comma : Extension<
   "commas at the end of enumerator lists are a %select{C99|C++0x}0-specific "
   "feature">;
+def err_enumerator_list_missing_comma : Error<
+  "missing ',' between enumerators">;
 
 def ext_gnu_indirect_goto : Extension<
   "use of GNU indirect-goto extension">, InGroup<GNU>;
index 555fcf0dec558164e2230877c05a959a923cd4a6..cf0cc9c4aa2fcfba396487f526ba345697af72ba 100644 (file)
@@ -2127,6 +2127,14 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) {
     EnumConstantDecls.push_back(EnumConstDecl);
     LastEnumConstDecl = EnumConstDecl;
 
+    if (Tok.is(tok::identifier)) {
+      // We're missing a comma between enumerators.
+      SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation);
+      Diag(Loc, diag::err_enumerator_list_missing_comma)      
+        << FixItHint::CreateInsertion(Loc, ", ");
+      continue;
+    }
+    
     if (Tok.isNot(tok::comma))
       break;
     SourceLocation CommaLoc = ConsumeToken();
index 6a63986f4a5a6c61959029f34433f5f70fefce7d..67d498523957d50aabffb4720f7a539049029003 100644 (file)
@@ -1737,11 +1737,11 @@ void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) {
       break;
     // If the next token looks like a base or member initializer, assume that
     // we're just missing a comma.
-    else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon))
-      Diag(Tok.getLocation(), diag::err_ctor_init_missing_comma)
-        << FixItHint::CreateInsertion(PP.getLocForEndOfToken(PrevTokLocation),
-                                      ", ");
-    else {
+    else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) {
+      SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation);
+      Diag(Loc, diag::err_ctor_init_missing_comma)
+        << FixItHint::CreateInsertion(Loc, ", ");
+    else {
       // Skip over garbage, until we get to '{'.  Don't eat the '{'.
       Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma);
       SkipUntil(tok::l_brace, true, true);
index 890fb10b41d5c732e8e35ab4a3497803a7f4f7fc..9c74435942838d0ff8a15129b1d3032d8a13efb7 100644 (file)
@@ -41,3 +41,10 @@ int test_cond(int y, int fooBar) {
 
 // CHECK: typedef int int_t;
 typedef typedef int int_t;
+
+// <rdar://problem/7159693>
+enum Color { 
+  Red // expected-error{{missing ',' between enumerators}}
+  Green = 17 // expected-error{{missing ',' between enumerators}}
+  Blue,
+};