summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Parse/ParseStmt.cpp13
-rw-r--r--clang/test/Index/unmatched-braces.c9
-rw-r--r--clang/test/Index/unmatched-braces.m11
3 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 5fe5e6a2b6a..79b53c3b245 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -823,17 +823,20 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
Stmts.push_back(R.release());
}
+ SourceLocation CloseLoc = Tok.getLocation();
+
// We broke out of the while loop because we found a '}' or EOF.
if (Tok.isNot(tok::r_brace)) {
Diag(Tok, diag::err_expected_rbrace);
Diag(T.getOpenLocation(), diag::note_matching) << "{";
- return StmtError();
+ // Recover by creating a compound statement with what we parsed so far,
+ // instead of dropping everything and returning StmtError();
+ } else {
+ if (!T.consumeClose())
+ CloseLoc = T.getCloseLocation();
}
- if (T.consumeClose())
- return StmtError();
-
- return Actions.ActOnCompoundStmt(T.getOpenLocation(), T.getCloseLocation(),
+ return Actions.ActOnCompoundStmt(T.getOpenLocation(), CloseLoc,
move_arg(Stmts), isStmtExpr);
}
diff --git a/clang/test/Index/unmatched-braces.c b/clang/test/Index/unmatched-braces.c
new file mode 100644
index 00000000000..b994605d362
--- /dev/null
+++ b/clang/test/Index/unmatched-braces.c
@@ -0,0 +1,9 @@
+void foo() {
+ int x;
+ if (x) {
+}
+
+// RUN: c-index-test -cursor-at=%s:2:7 %s > %t
+// RUN: FileCheck %s -input-file %t
+
+// CHECK: VarDecl=x:2:7
diff --git a/clang/test/Index/unmatched-braces.m b/clang/test/Index/unmatched-braces.m
new file mode 100644
index 00000000000..84fe82a0667
--- /dev/null
+++ b/clang/test/Index/unmatched-braces.m
@@ -0,0 +1,11 @@
+@implementation I
+-(void)meth {
+ int x;
+ if (x) {
+}
+@end
+
+// RUN: c-index-test -cursor-at=%s:3:7 %s > %t
+// RUN: FileCheck %s -input-file %t
+
+// CHECK: VarDecl=x:3:7
OpenPOWER on IntegriCloud