]> granicus.if.org Git - clang/commitdiff
Remove "parse error" in favor of more descriptive diagnostics.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 6 Apr 2012 23:33:59 +0000 (23:33 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 6 Apr 2012 23:33:59 +0000 (23:33 +0000)
In a few cases clang emitted a rather content-free diagnostic: 'parse error'.
This change replaces two actual cases (template parameter parsing and K&R
parameter declaration parsing) with more specific diagnostics and removes a
third dead case of this in the BalancedDelimiterTracker (the ctor already
checked the invariant necessary to ensure that the diag::parse_error was never
actually used).

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseTemplate.cpp
lib/Parse/Parser.cpp
test/Parser/cxx-template-decl.cpp
test/Parser/declarators.c

index 33657a1553986c4521af1ace45ee85a756b47812..81c38e7da5ace46078c510dcda2d7dc2b06bca5c 100644 (file)
@@ -117,7 +117,6 @@ def ext_gnu_case_range : Extension<"use of GNU case range extension">,
   InGroup<GNU>;
 
 // Generic errors.
-def err_parse_error : Error<"parse error">;
 def err_expected_expression : Error<"expected expression">;
 def err_expected_type : Error<"expected a type">;
 def err_expected_external_declaration : Error<"expected external declaration">;
@@ -506,6 +505,7 @@ def err_explicit_instantiation_with_definition : Error<
 def err_enum_template : Error<"enumeration cannot be a template">;
 def err_explicit_instantiation_enum : Error<
     "enumerations cannot be explicitly instantiated">;
+def err_expected_template_parameter : Error<"expected template parameter">;
 
 def err_missing_dependent_template_keyword : Error<
   "use 'template' keyword to treat '%0' as a dependent template name">;
index b7cc862b4da9a69adbd855c798dfa0a7e1d6719d..9d5c62567e4938471e8798b10d84bc47fe8b6dbf 100644 (file)
@@ -638,12 +638,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
   Declarator ParamDecl(DS, Declarator::TemplateParamContext);
   ParseDeclarator(ParamDecl);
   if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) {
-    // This probably shouldn't happen - and it's more of a Sema thing, but
-    // basically we didn't parse the type name because we couldn't associate
-    // it with an AST node. we should just skip to the comma or greater.
-    // TODO: This is currently a placeholder for some kind of Sema Error.
-    Diag(Tok.getLocation(), diag::err_parse_error);
-    SkipUntil(tok::comma, tok::greater, true, true);
+    Diag(Tok.getLocation(), diag::err_expected_template_parameter);
     return 0;
   }
 
index dd339f53948b4d650a5ccd290d12af5e423920d3..2c6dff35b272346f46be1347e2cd5db5e33e3359 100644 (file)
@@ -1111,7 +1111,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
     if (Tok.is(tok::semi)) {
       ConsumeToken();
     } else {
-      Diag(Tok, diag::err_parse_error);
+      Diag(Tok, diag::err_expected_semi_declaration);
       // Skip to end of block or statement
       SkipUntil(tok::semi, true);
       if (Tok.is(tok::semi))
@@ -1681,9 +1681,9 @@ bool Parser::BalancedDelimiterTracker::diagnoseMissingClose() {
   assert(!P.Tok.is(Close) && "Should have consumed closing delimiter");
   
   const char *LHSName = "unknown";
-  diag::kind DID = diag::err_parse_error;
+  diag::kind DID;
   switch (Close) {
-  default: break;
+  default: llvm_unreachable("Unexpected balanced token");
   case tok::r_paren : LHSName = "("; DID = diag::err_expected_rparen; break;
   case tok::r_brace : LHSName = "{"; DID = diag::err_expected_rbrace; break;
   case tok::r_square: LHSName = "["; DID = diag::err_expected_rsquare; break;
index 870be930a6fcaddf48fd87c6a0c4f7d8b3411077..be1f81e9d15a516a4fbef731c3e008ba20acacfd 100644 (file)
@@ -6,7 +6,7 @@ template  x;            // expected-error {{C++ requires a type specifier for al
                         // expected-error {{does not refer}}
 export template x;      // expected-error {{expected '<' after 'template'}}
 export template<class T> class x0; // expected-warning {{exported templates are unsupported}}
-template < ;            // expected-error {{parse error}} \
+template < ;            // expected-error {{expected template parameter}} \
 // expected-error{{expected ',' or '>' in template-parameter-list}} \
 // expected-warning {{declaration does not declare anything}}
 template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \
index e245adb7cded037dc62a9e236517b65f4a6a2044..a7a01d8b4e8383d2a935195ce0c08b7ea7f453bf 100644 (file)
@@ -97,3 +97,6 @@ void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.
 
 // rdar://problem/8358508
 long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}}
+
+void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}}
+void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}}