diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-23 05:45:25 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-23 05:45:25 +0000 |
commit | eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0 (patch) | |
tree | ae1948b1996d0c59ea4f597701504ea5e8caa25c /lib | |
parent | 3fe52ff7df93f7a928a15cc2cbf5134fdc0cec15 (diff) |
Add diagnostics for comma at end of enum and for extra semicolon at namespace
scope to -Wc++11-extensions. Move extra semicolon after member function
definition diagnostic out of -pedantic, since C++ allows a single semicolon
there. Keep it in -Wextra-semi, though, since it's still questionable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160618 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 8 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 8 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 31 |
3 files changed, 27 insertions, 20 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 38aff5d4b9..9e58b312e3 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2876,8 +2876,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, // Check for extraneous top-level semicolon. if (Tok.is(tok::semi)) { - ConsumeExtraSemi(InsideStruct, - DeclSpec::getSpecifierName((DeclSpec::TST)TagType)); + ConsumeExtraSemi(InsideStruct, TagType); continue; } @@ -3373,8 +3372,9 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { if (Tok.isNot(tok::identifier)) { if (!getLangOpts().C99 && !getLangOpts().CPlusPlus0x) - Diag(CommaLoc, diag::ext_enumerator_list_comma) - << getLangOpts().CPlusPlus + Diag(CommaLoc, getLangOpts().CPlusPlus ? + diag::ext_enumerator_list_comma_cxx : + diag::ext_enumerator_list_comma_c) << FixItHint::CreateRemoval(CommaLoc); else if (getLangOpts().CPlusPlus0x) Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma) diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 8e357f7e42..3dc96cf0d2 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1984,7 +1984,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // Consume the ';' - it's optional unless we have a delete or default if (Tok.is(tok::semi)) - ConsumeExtraSemi(AfterDefinition); + ConsumeExtraSemi(AfterMemberFunctionDefinition); return; } @@ -2334,8 +2334,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, // Check for extraneous top-level semicolon. if (Tok.is(tok::semi)) { - ConsumeExtraSemi(InsideStruct, - DeclSpec::getSpecifierName((DeclSpec::TST)TagType)); + ConsumeExtraSemi(InsideStruct, TagType); continue; } @@ -3060,8 +3059,7 @@ void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, // Check for extraneous top-level semicolon. if (Tok.is(tok::semi)) { - ConsumeExtraSemi(InsideStruct, - DeclSpec::getSpecifierName((DeclSpec::TST)TagType)); + ConsumeExtraSemi(InsideStruct, TagType); continue; } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 760c7bf717..7314228b9f 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -220,31 +220,40 @@ bool Parser::ExpectAndConsumeSemi(unsigned DiagID) { return ExpectAndConsume(tok::semi, DiagID); } -void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, const char* DiagMsg) { +void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST) { if (!Tok.is(tok::semi)) return; - // AfterDefinition should only warn when placed on the same line as the - // definition. Otherwise, defer to another semi warning. - if (Kind == AfterDefinition && Tok.isAtStartOfLine()) return; - + bool HadMultipleSemis = false; SourceLocation StartLoc = Tok.getLocation(); SourceLocation EndLoc = Tok.getLocation(); ConsumeToken(); while ((Tok.is(tok::semi) && !Tok.isAtStartOfLine())) { + HadMultipleSemis = true; EndLoc = Tok.getLocation(); ConsumeToken(); } - if (Kind == OutsideFunction && getLangOpts().CPlusPlus0x) { - Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi) - << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); + // C++11 allows extra semicolons at namespace scope, but not in any of the + // other contexts. + if (Kind == OutsideFunction && getLangOpts().CPlusPlus) { + if (getLangOpts().CPlusPlus0x) + Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi) + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); + else + Diag(StartLoc, diag::ext_extra_semi_cxx11) + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); return; } - Diag(StartLoc, diag::ext_extra_semi) - << Kind << DiagMsg << FixItHint::CreateRemoval(SourceRange(StartLoc, - EndLoc)); + if (Kind != AfterMemberFunctionDefinition || HadMultipleSemis) + Diag(StartLoc, diag::ext_extra_semi) + << Kind << DeclSpec::getSpecifierName((DeclSpec::TST)TST) + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); + else + // A single semicolon is valid after a member function definition. + Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def) + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); } //===----------------------------------------------------------------------===// |