diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-09 22:31:44 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-09 22:31:44 +0000 |
commit | 1c94c16317c1a35c1549e022958188eea2567089 (patch) | |
tree | df3c9667a969fdc0872a1ca42c5d2c54dd9fba04 /lib/Parse/ParseDeclCXX.cpp | |
parent | d1d512a9cd1923566a52e57b7e1e8ae65392f66b (diff) |
Extend the diagnostic for a ',' at the end of a declaration where a ';' was
intended to cover C++ class definitions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 5bae0e4d2c..05a346353b 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1548,13 +1548,13 @@ void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, } } -/// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x +/// isCXX0XVirtSpecifier - Determine whether the given token is a C++0x /// virt-specifier. /// /// virt-specifier: /// override /// final -VirtSpecifiers::Specifier Parser::isCXX0XVirtSpecifier() const { +VirtSpecifiers::Specifier Parser::isCXX0XVirtSpecifier(const Token &Tok) const { if (!getLang().CPlusPlus) return VirtSpecifiers::VS_None; @@ -1896,6 +1896,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, SmallVector<Decl *, 8> DeclsInGroup; ExprResult BitfieldSize; + bool ExpectSemi = true; while (1) { // member-declarator: @@ -2023,7 +2024,18 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, break; // Consume the comma. - ConsumeToken(); + SourceLocation CommaLoc = ConsumeToken(); + + if (Tok.isAtStartOfLine() && + !MightBeDeclarator(Declarator::MemberContext)) { + // This comma was followed by a line-break and something which can't be + // the start of a declarator. The comma was probably a typo for a + // semicolon. + Diag(CommaLoc, diag::err_expected_semi_declaration) + << FixItHint::CreateReplacement(CommaLoc, ";"); + ExpectSemi = false; + break; + } // Parse the next declarator. DeclaratorInfo.clear(); @@ -2039,7 +2051,8 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, ParseDeclarator(DeclaratorInfo); } - if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { + if (ExpectSemi && + 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. |