aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2011-06-13 05:50:12 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2011-06-13 05:50:12 +0000
commit0e1e69ca1b30df7692f302a5388377f507bc4567 (patch)
tree08e99a882fc1e9b343f4fe5e9fa0e03624b10650 /lib/Parse/ParseStmt.cpp
parent5fc99f3cb7a18f5306b4ed6f58f1a397e7fb7696 (diff)
Improve the diagnostics generated for switch statements missing expressions
- Move the diagnostic to the case statement instead of at the end of the switch - Add a fix-it hint as to how to fix the compilation error git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132903 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r--lib/Parse/ParseStmt.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 6cc8b57b61..6b4a0a4045 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -502,6 +502,7 @@ StmtResult Parser::ParseCaseStatement(ParsedAttributes &attrs, bool MissingCase,
StmtTy *DeepestParsedCaseStmt = 0;
// While we have case statements, eat and stack them.
+ SourceLocation ColonLoc;
do {
SourceLocation CaseLoc = MissingCase ? Expr.get()->getExprLoc() :
ConsumeToken(); // eat the 'case'.
@@ -539,7 +540,6 @@ StmtResult Parser::ParseCaseStatement(ParsedAttributes &attrs, bool MissingCase,
ColonProtection.restore();
- SourceLocation ColonLoc;
if (Tok.is(tok::colon)) {
ColonLoc = ConsumeToken();
@@ -589,8 +589,9 @@ StmtResult Parser::ParseCaseStatement(ParsedAttributes &attrs, bool MissingCase,
} else {
// Nicely diagnose the common error "switch (X) { case 4: }", which is
// not valid.
- // FIXME: add insertion hint.
- Diag(Tok, diag::err_label_end_of_compound_statement);
+ SourceLocation ExpectedLoc = PP.getLocForEndOfToken(ColonLoc);
+ Diag(ExpectedLoc, diag::err_label_end_of_compound_statement)
+ << FixItHint::CreateInsertion(ExpectedLoc, ";");
SubStmt = true;
}
@@ -634,7 +635,9 @@ StmtResult Parser::ParseDefaultStatement(ParsedAttributes &attrs) {
// 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);
+ SourceLocation ExpectedLoc = PP.getLocForEndOfToken(ColonLoc);
+ Diag(ExpectedLoc, diag::err_label_end_of_compound_statement)
+ << FixItHint::CreateInsertion(ExpectedLoc, ";");
return StmtError();
}