From: Chris Lattner Date: Sat, 28 Apr 2012 16:12:17 +0000 (+0000) Subject: switch some uses of ExpectAndConsume(tok::semi to use ExpectAndConsumeSemi. This... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bb21d32e9ccc9d9c221506dff26acafa8724cca;p=clang switch some uses of ExpectAndConsume(tok::semi to use ExpectAndConsumeSemi. This allows 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 --- diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 1c0815a669..082e335aae 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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. diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 44320dfcb3..8dd0a2a5dc 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -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()); } diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 5c3e2ba589..d906782609 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -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); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index a28341028e..0d6f7dd897 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -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)) diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index a7a01d8b4e..476a9af0fd 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -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 ';'}} +} +