summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-12-23 22:56:40 +0000
committerDouglas Gregor <dgregor@apple.com>2010-12-23 22:56:40 +0000
commit0d0a965b62ca5acd4dddffc5621f998b291b80a4 (patch)
tree119d33c712974643be7eb223feb20c3693e5626c /clang/lib/Parse/ParseStmt.cpp
parent36be00ceb3c5cbb8fee4368fe424abbc4eaa4bf9 (diff)
downloadbcm5719-llvm-0d0a965b62ca5acd4dddffc5621f998b291b80a4.tar.gz
bcm5719-llvm-0d0a965b62ca5acd4dddffc5621f998b291b80a4.zip
Improve the diagnostic and recovery for missing colons after 'case'
and 'default' statements, including a Fix-It to add the colon: test/Parser/switch-recovery.cpp:13:12: error: expected ':' after 'case' case 17 // expected-error{{expected ':' after 'case'}} ^ : test/Parser/switch-recovery.cpp:16:12: error: expected ':' after 'default' default // expected-error{{expected ':' after 'default'}} ^ : llvm-svn: 122522
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
-rw-r--r--clang/lib/Parse/ParseStmt.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 29779070bee..437a950cd94 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -315,14 +315,16 @@ StmtResult Parser::ParseCaseStatement(AttributeList *Attr) {
ColonProtection.restore();
+ SourceLocation ColonLoc;
if (Tok.isNot(tok::colon)) {
- Diag(Tok, diag::err_expected_colon_after) << "'case'";
- SkipUntil(tok::colon);
- return StmtError();
+ SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
+ Diag(ExpectedLoc, diag::err_expected_colon_after) << "'case'"
+ << FixItHint::CreateInsertion(ExpectedLoc, ":");
+ ColonLoc = ExpectedLoc;
+ } else {
+ ColonLoc = ConsumeToken();
}
-
- SourceLocation ColonLoc = ConsumeToken();
-
+
StmtResult Case =
Actions.ActOnCaseStmt(CaseLoc, LHS.get(), DotDotDotLoc,
RHS.get(), ColonLoc);
@@ -384,14 +386,16 @@ StmtResult Parser::ParseDefaultStatement(AttributeList *Attr) {
assert(Tok.is(tok::kw_default) && "Not a default stmt!");
SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'.
+ SourceLocation ColonLoc;
if (Tok.isNot(tok::colon)) {
- Diag(Tok, diag::err_expected_colon_after) << "'default'";
- SkipUntil(tok::colon);
- return StmtError();
+ SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
+ Diag(ExpectedLoc, diag::err_expected_colon_after) << "'default'"
+ << FixItHint::CreateInsertion(ExpectedLoc, ":");
+ ColonLoc = ExpectedLoc;
+ } else {
+ ColonLoc = ConsumeToken();
}
-
- SourceLocation ColonLoc = ConsumeToken();
-
+
// Diagnose the common error "switch (X) {... default: }", which is not valid.
if (Tok.is(tok::r_brace)) {
Diag(Tok, diag::err_label_end_of_compound_statement);
OpenPOWER on IntegriCloud