]> granicus.if.org Git - clang/commitdiff
Do proper recovery from an invalid switch condiition. Fixes PR3229.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 17 Dec 2008 22:19:57 +0000 (22:19 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 17 Dec 2008 22:19:57 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61160 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseStmt.cpp
test/Parser/recovery.c

index 9f8771c9193b857acebfb845997ec8dc4250a180..d22fbb7044648d281f00c62ca043dd4b82c7cd05 100644 (file)
@@ -611,9 +611,10 @@ Parser::OwningStmtResult Parser::ParseSwitchStatement() {
   OwningExprResult Cond(Actions);
   if (ParseParenExprOrCondition(Cond))
     return StmtError();
-  
-  OwningStmtResult Switch(Actions,
-                          Actions.ActOnStartOfSwitchStmt(Cond.release()));
+
+  OwningStmtResult Switch(Actions);
+  if (!Cond.isInvalid())
+    Switch = Actions.ActOnStartOfSwitchStmt(Cond.release());
 
   // C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if
   // there is no compound stmt.  C90 does not have this clause.  We only do this
index 78addb90e492c6d5d9ac2233dafbe219476bb5ef..ea5951604192451a5e4fcb34edf28edc1e266d87 100644 (file)
@@ -65,3 +65,6 @@ int test6248081() {
   [10]  // expected-error {{expected expression}}
 }
 
+struct forward;
+void x(struct forward* x) {switch(x->a) {}}
+