]> granicus.if.org Git - clang/commitdiff
switch some uses of ExpectAndConsume(tok::semi to use ExpectAndConsumeSemi. This...
authorChris Lattner <sabre@nondot.org>
Sat, 28 Apr 2012 16:12:17 +0000 (16:12 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 28 Apr 2012 16:12:17 +0000 (16:12 +0000)
us to improve this diagnostic (telling us to insert another ")":

t.c:2:19: error: expected ';' at end of declaration
  int x = 4+(5-12));
                  ^
                  ;
to:
t.c:2:19: error: extraneous ')' before ';'
  int x = 4+(5-12));
                  ^

...telling us to remove the ")".  This is PR12595.  There are more uses of ExpectAndConsumeSemi
that could be switched over, but I don't hit them on a daily basis :)

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

lib/Parse/ParseDecl.cpp
lib/Parse/ParseStmt.cpp
lib/Parse/ParseTemplate.cpp
lib/Parse/Parser.cpp
test/Parser/declarators.c

index 1c0815a669b6c4fdf30252fa10b2381d298890fb..082e335aaef67034ae66ca1a2df94cf6c625bd5c 100644 (file)
@@ -1312,10 +1312,9 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
     *DeclEnd = Tok.getLocation();
 
   if (ExpectSemi &&
-      ExpectAndConsume(tok::semi,
-                       Context == Declarator::FileContext
-                         ? diag::err_invalid_token_after_toplevel_declarator
-                         : diag::err_expected_semi_declaration)) {
+      ExpectAndConsumeSemi(Context == Declarator::FileContext
+                           ? diag::err_invalid_token_after_toplevel_declarator
+                           : diag::err_expected_semi_declaration)) {
     // Okay, there was no semicolon and one was expected.  If we see a
     // declaration specifier, just assume it was missing and continue parsing.
     // Otherwise things are very confused and we skip to recover.
index 44320dfcb3bf78a6df522d9fffc87d6dc52d6b31..8dd0a2a5dc81933bbb0715d5514fac1d29d1a1f8 100644 (file)
@@ -771,7 +771,7 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
                                       DeclsInGroup.data(), DeclsInGroup.size());
     StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc, Tok.getLocation());
 
-    ExpectAndConsume(tok::semi, diag::err_expected_semi_declaration);
+    ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
     if (R.isUsable())
       Stmts.push_back(R.release());
   }
index 5c3e2ba589ff457092e6b0181e17dfed9cd26547..d9067826096b73215c2c380ebfd03b4368d88123 100644 (file)
@@ -259,7 +259,7 @@ Parser::ParseSingleDeclarationAfterTemplate(
     }
 
     // Eat the semi colon after the declaration.
-    ExpectAndConsume(tok::semi, diag::err_expected_semi_declaration);
+    ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
     if (LateParsedAttrs.size() > 0)
       ParseLexedAttributeList(LateParsedAttrs, ThisDecl, true, false);
     DeclaratorInfo.complete(ThisDecl);
index a28341028e98ee2d16ed033c00cbc1fade4a88af..0d6f7dd897b15d1eb26a73eaa28ab5e907e1fe92 100644 (file)
@@ -1130,10 +1130,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
       ParseDeclarator(ParmDeclarator);
     }
 
-    if (Tok.is(tok::semi)) {
-      ConsumeToken();
-    } else {
-      Diag(Tok, diag::err_expected_semi_declaration);
+    if (ExpectAndConsumeSemi(diag::err_expected_semi_declaration)) {
       // Skip to end of block or statement
       SkipUntil(tok::semi, true);
       if (Tok.is(tok::semi))
index a7a01d8b4e8383d2a935195ce0c08b7ea7f453bf..476a9af0fd9b7e68047d28a1de7177a24b2d2a3d 100644 (file)
@@ -100,3 +100,10 @@ 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}}
+
+
+// PR12595
+void test18() {
+  int x = 4+(5-12));  // expected-error {{extraneous ')' before ';'}}
+}
+