]> granicus.if.org Git - clang/commitdiff
Don't skip past the '}' if an expression has error and is not followed by ';'.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 31 Mar 2010 00:37:59 +0000 (00:37 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 31 Mar 2010 00:37:59 +0000 (00:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99972 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseStmt.cpp
test/Index/recover-bad-code-rdar_7487294.c
test/Parser/statements.c

index 9fd145dc2676f9ebe43881bc837c08224f36ac04..b752b48cfd49fc0a410d6fb433db5aaa64114a5e 100644 (file)
@@ -125,10 +125,12 @@ Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
     // expression[opt] ';'
     OwningExprResult Expr(ParseExpression());
     if (Expr.isInvalid()) {
-      // If the expression is invalid, skip ahead to the next semicolon.  Not
-      // doing this opens us up to the possibility of infinite loops if
+      // If the expression is invalid, skip ahead to the next semicolon or '}'.
+      // Not doing this opens us up to the possibility of infinite loops if
       // ParseExpression does not consume any tokens.
-      SkipUntil(tok::semi);
+      SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true);
+      if (Tok.is(tok::semi))
+        ConsumeToken();
       return StmtError();
     }
     // Otherwise, eat the semicolon.
index 97bb5158e4728c53e44b092fd31d8465e3d8e031..e060672b692395ffa74e37c9d52b2826e99f4452 100644 (file)
@@ -11,4 +11,3 @@ int foo(int x) {
 
 // CHECK: 9:3: error: use of undeclared identifier 'help'
 // CHECK:  help
-// CHECK: 14:102: error: expected '}'
index a662c9b821185f1324f30242acdb78a9ef02e5d8..bc7192a7b2b3295ef0c5603bd06215e75b4e6d70 100644 (file)
@@ -57,3 +57,8 @@ void test6(void) {
 int test7() {
   return 4     // expected-error {{expected ';' after return statement}}
 }
+
+void test8() {
+  // Should not skip '}' and produce a "expected '}'" error.
+  undecl // expected-error {{use of undeclared identifier 'undecl'}}
+}