diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-09-07 14:51:08 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-09-07 14:51:08 +0000 |
| commit | ce66d028771d0ed37d3eba8c83e9193734b7cf06 (patch) | |
| tree | 1f1e31cdd723b6e709225f1a2b5e725339d7ee0a | |
| parent | 1ecb978214f7522be9348c0770cabd3014528cba (diff) | |
| download | bcm5719-llvm-ce66d028771d0ed37d3eba8c83e9193734b7cf06.tar.gz bcm5719-llvm-ce66d028771d0ed37d3eba8c83e9193734b7cf06.zip | |
Improve recovery when a comma is missing between enumerators in an
enumeration definition. Fixes <rdar://problem/7159693>.
llvm-svn: 113201
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 10 | ||||
| -rw-r--r-- | clang/test/FixIt/fixit.c | 7 |
4 files changed, 22 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 50e98706f51..28cd2d98f07 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -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>; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 555fcf0dec5..cf0cc9c4aa2 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -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(); diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6a63986f4a5..67d49852395 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -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); diff --git a/clang/test/FixIt/fixit.c b/clang/test/FixIt/fixit.c index 890fb10b41d..9c744359428 100644 --- a/clang/test/FixIt/fixit.c +++ b/clang/test/FixIt/fixit.c @@ -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, +}; |

