diff options
author | Richard Trieu <rtrieu@google.com> | 2012-05-16 19:04:59 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2012-05-16 19:04:59 +0000 |
commit | 2f7dc46a5868db54f5a96e3a7308cad6970c0e4b (patch) | |
tree | e6c0a659e4d59be74b1b89330ea5f7228797b616 /clang/lib/Parse/Parser.cpp | |
parent | 8c17fbd6c167687fca630b91ba007265e6a9c424 (diff) | |
download | bcm5719-llvm-2f7dc46a5868db54f5a96e3a7308cad6970c0e4b.tar.gz bcm5719-llvm-2f7dc46a5868db54f5a96e3a7308cad6970c0e4b.zip |
Move the warnings for extra semi-colons under -Wextra-semi. Also, added
a warning for an extra semi-colon after function definitions. Added logic
so that a block of semi-colons on a line will only get one warning instead
of a warning for each semi-colon.
llvm-svn: 156934
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index ad283fa57a6..504071405b7 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -202,6 +202,33 @@ bool Parser::ExpectAndConsumeSemi(unsigned DiagID) { return ExpectAndConsume(tok::semi, DiagID); } +void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, const char* DiagMsg) { + 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; + + SourceLocation StartLoc = Tok.getLocation(); + SourceLocation EndLoc = Tok.getLocation(); + ConsumeToken(); + + while ((Tok.is(tok::semi) && !Tok.isAtStartOfLine())) { + EndLoc = Tok.getLocation(); + ConsumeToken(); + } + + if (Kind == OutsideFunction && getLangOpts().CPlusPlus0x) { + Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi) + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); + return; + } + + Diag(StartLoc, diag::ext_extra_semi) + << Kind << DiagMsg << FixItHint::CreateRemoval(SourceRange(StartLoc, + EndLoc)); +} + //===----------------------------------------------------------------------===// // Error recovery. //===----------------------------------------------------------------------===// @@ -582,11 +609,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, HandlePragmaPack(); return DeclGroupPtrTy(); case tok::semi: - Diag(Tok, getLangOpts().CPlusPlus0x ? - diag::warn_cxx98_compat_top_level_semi : diag::ext_top_level_semi) - << FixItHint::CreateRemoval(Tok.getLocation()); - - ConsumeToken(); + ConsumeExtraSemi(OutsideFunction); // TODO: Invoke action for top-level semicolon. return DeclGroupPtrTy(); case tok::r_brace: |