[cfe-commits] r124025 - in /cfe/trunk: lib/Parse/ParseStmt.cpp test/Parser/switch-recovery.cpp
John McCall
rjmccall at apple.com
Sat Jan 22 01:28:32 PST 2011
Author: rjmccall
Date: Sat Jan 22 03:28:32 2011
New Revision: 124025
URL: http://llvm.org/viewvc/llvm-project?rev=124025&view=rev
Log:
Improve our parse recovery on 'case blah;' and 'default;'.
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/Parser/switch-recovery.cpp
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=124025&r1=124024&r2=124025&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Jan 22 03:28:32 2011
@@ -311,13 +311,19 @@
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 @@
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.
Modified: cfe/trunk/test/Parser/switch-recovery.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/switch-recovery.cpp?rev=124025&r1=124024&r2=124025&view=diff
==============================================================================
--- cfe/trunk/test/Parser/switch-recovery.cpp (original)
+++ cfe/trunk/test/Parser/switch-recovery.cpp Sat Jan 22 03:28:32 2011
@@ -17,4 +17,18 @@
return;
}
}
+
+ void test2() {
+ enum X { Xa, Xb } x;
+
+ switch (x) { // expected-warning {{enumeration value 'Xb' not handled in switch}}
+ case Xa; // expected-error {{expected ':' after 'case'}}
+ break;
+ }
+
+ switch (x) {
+ default; // expected-error {{expected ':' after 'default'}}
+ break;
+ }
+ }
};
More information about the cfe-commits
mailing list