[cfe-commits] r104291 - in /cfe/trunk: lib/Parse/ParseStmt.cpp test/Parser/switch-recovery.cpp

Douglas Gregor dgregor at apple.com
Thu May 20 16:20:59 PDT 2010


Author: dgregor
Date: Thu May 20 18:20:59 2010
New Revision: 104291

URL: http://llvm.org/viewvc/llvm-project?rev=104291&view=rev
Log:
Improve parser recovery when a switch condition is invalid; fixes
<rdar://problem/7971948>.

Added:
    cfe/trunk/test/Parser/switch-recovery.cpp
Modified:
    cfe/trunk/lib/Parse/ParseStmt.cpp

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=104291&r1=104290&r2=104291&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Thu May 20 18:20:59 2010
@@ -754,9 +754,10 @@
     // FIXME: This is not optimal recovery, but parsing the body is more
     // dangerous due to the presence of case and default statements, which
     // will have no place to connect back with the switch.
-    if (Tok.is(tok::l_brace))
-      MatchRHSPunctuation(tok::r_brace, ConsumeBrace());
-    else
+    if (Tok.is(tok::l_brace)) {
+      ConsumeBrace();
+      SkipUntil(tok::r_brace, false, false);
+    } else
       SkipUntil(tok::semi);
     return move(Switch);
   }

Added: cfe/trunk/test/Parser/switch-recovery.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/switch-recovery.cpp?rev=104291&view=auto
==============================================================================
--- cfe/trunk/test/Parser/switch-recovery.cpp (added)
+++ cfe/trunk/test/Parser/switch-recovery.cpp Thu May 20 18:20:59 2010
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/7971948>
+struct A {};
+struct B {
+  void foo() {
+    switch (a) { // expected-error{{use of undeclared identifier 'a'}}
+    default:
+      return;
+    }
+  }
+};





More information about the cfe-commits mailing list