summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-01-22 09:28:32 +0000
committerJohn McCall <rjmccall@apple.com>2011-01-22 09:28:32 +0000
commit0140bfeead0452e7144e449b86f3fa581a020617 (patch)
treebfbe86269bf532f413d03e2ca696d33f4f82187b /clang/lib
parent6ed95945edea5f40fa5aedb3b049bb3d78dcce4e (diff)
downloadbcm5719-llvm-0140bfeead0452e7144e449b86f3fa581a020617.tar.gz
bcm5719-llvm-0140bfeead0452e7144e449b86f3fa581a020617.zip
Improve our parse recovery on 'case blah;' and 'default;'.
llvm-svn: 124025
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Parse/ParseStmt.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 3a6f80da2d9..5f932919b92 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -311,13 +311,19 @@ StmtResult Parser::ParseCaseStatement(ParsedAttributes &attrs) {
ColonProtection.restore();
SourceLocation ColonLoc;
- if (Tok.isNot(tok::colon)) {
+ if (Tok.is(tok::colon)) {
+ ColonLoc = ConsumeToken();
+
+ // Treat "case blah;" as a typo for "case blah:".
+ } else if (Tok.is(tok::semi)) {
+ ColonLoc = ConsumeToken();
+ Diag(ColonLoc, diag::err_expected_colon_after) << "'case'"
+ << FixItHint::CreateReplacement(ColonLoc, ":");
+ } else {
SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
Diag(ExpectedLoc, diag::err_expected_colon_after) << "'case'"
<< FixItHint::CreateInsertion(ExpectedLoc, ":");
ColonLoc = ExpectedLoc;
- } else {
- ColonLoc = ConsumeToken();
}
StmtResult Case =
@@ -382,13 +388,19 @@ StmtResult Parser::ParseDefaultStatement(ParsedAttributes &attrs) {
SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'.
SourceLocation ColonLoc;
- if (Tok.isNot(tok::colon)) {
+ if (Tok.is(tok::colon)) {
+ ColonLoc = ConsumeToken();
+
+ // Treat "default;" as a typo for "default:".
+ } else if (Tok.is(tok::semi)) {
+ ColonLoc = ConsumeToken();
+ Diag(ColonLoc, diag::err_expected_colon_after) << "'default'"
+ << FixItHint::CreateReplacement(ColonLoc, ":");
+ } else {
SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
Diag(ExpectedLoc, diag::err_expected_colon_after) << "'default'"
<< FixItHint::CreateInsertion(ExpectedLoc, ":");
ColonLoc = ExpectedLoc;
- } else {
- ColonLoc = ConsumeToken();
}
// Diagnose the common error "switch (X) {... default: }", which is not valid.
OpenPOWER on IntegriCloud