From ae50d501f463d7032320ec31840f60ae68df3a55 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 2 Feb 2010 00:43:15 +0000 Subject: [PATCH] improve diagnostics for C++ struct ; issues. Before: t.cc:4:3: error: expected ';' at end of declaration list int y; ^ t.cc:6:1: error: expected ';' at end of declaration list }; ^ After: t.cc:3:8: error: expected ';' at end of declaration list int x ^ ; t.cc:5:8: error: expected ';' at end of declaration list int z ^ ; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95039 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDeclCXX.cpp | 20 ++++++++------------ test/Parser/cxx-decl.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 87bb3cb2b1..e83743cd67 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1189,8 +1189,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, if (Tok.is(tok::kw_namespace)) { Diag(UsingLoc, diag::err_using_namespace_in_class); SkipUntil(tok::semi, true, true); - } - else { + } else { SourceLocation DeclEnd; // Otherwise, it must be using-declaration. ParseUsingDeclaration(Declarator::MemberContext, UsingLoc, DeclEnd, AS); @@ -1371,19 +1370,16 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, ParseDeclarator(DeclaratorInfo); } - if (Tok.is(tok::semi)) { - ConsumeToken(); - Actions.FinalizeDeclaratorGroup(CurScope, DS, DeclsInGroup.data(), - DeclsInGroup.size()); + if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { + // Skip to end of block or statement. + SkipUntil(tok::r_brace, true, true); + // If we stopped at a ';', eat it. + if (Tok.is(tok::semi)) ConsumeToken(); return; } - Diag(Tok, diag::err_expected_semi_decl_list); - // Skip to end of block or statement - SkipUntil(tok::r_brace, true, true); - if (Tok.is(tok::semi)) - ConsumeToken(); - return; + Actions.FinalizeDeclaratorGroup(CurScope, DS, DeclsInGroup.data(), + DeclsInGroup.size()); } /// ParseCXXMemberSpecification - Parse the class definition. diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 3c88b7adfa..f37604cc54 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -52,3 +52,9 @@ void test(struct Type *P) { (y:b) // expected-error {{unexpected ':' in nested name specifier}} 4) : 5; } + +struct test4 { + int x // expected-error {{expected ';' at end of declaration list}} + int y; + int z // expected-error {{expected ';' at end of declaration list}} +}; -- 2.40.0