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'.
ColonProtection.restore();
- SourceLocation ColonLoc;
if (Tok.is(tok::colon)) {
ColonLoc = ConsumeToken();
} 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;
}
// 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();
}
}
}
}
+
+void missing_statement_case(int x) {
+ switch (x) {
+ case 1:
+ case 0: // expected-error {{label at end of compound statement: expected statement}}
+ }
+}
+
+void missing_statement_default(int x) {
+ switch (x) {
+ case 0:
+ default: // expected-error {{label at end of compound statement: expected statement}}
+ }
+}