aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2012-05-16 19:04:59 +0000
committerRichard Trieu <rtrieu@google.com>2012-05-16 19:04:59 +0000
commit4b0e6f1da341510c1ad83eaf4c836f3134d0156a (patch)
tree2dff3a69b5a063baa3ca503771b8cf6f5db4e9c5 /lib/Parse/Parser.cpp
parent533718fb27f87a25bf9f6fdd69df4a4ce8b783a6 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156934 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index ad283fa57a..504071405b 100644
--- a/lib/Parse/Parser.cpp
+++ b/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: