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 | 87f5dc53b23ebe4dceb0a2354d83d96f07a1024e (patch) | |
tree | cb997819257dc6ee1b990bc5e335034f37455847 /clang/lib/Parse/Parser.cpp | |
parent | 2694c05e8692fb95dbd9152a652394daa05d14a3 (diff) | |
download | bcm5719-llvm-87f5dc53b23ebe4dceb0a2354d83d96f07a1024e.tar.gz bcm5719-llvm-87f5dc53b23ebe4dceb0a2354d83d96f07a1024e.zip |
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.
llvm-svn: 160618
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 760c7bf717a..7314228b9f9 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/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)); } //===----------------------------------------------------------------------===// |