diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 75b5e11f8327c..7ae136af47391 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -6024,7 +6024,7 @@ Parser::DeclGroupPtrTy Parser::ParseTopLevelStmtDecl() { TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(getCurScope()); StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx); if (!R.isUsable()) - return nullptr; + R = Actions.ActOnNullStmt(Tok.getLocation()); Actions.ActOnFinishTopLevelStmtDecl(TLSD, R.get()); diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index 30b051e747f92..578f1d4c0eac6 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -107,6 +107,13 @@ TEST_F(InterpreterTest, Errors) { auto RecoverErr = Interp->Parse("int var1 = 42;"); EXPECT_TRUE(!!RecoverErr); + + Err = Interp->Parse("try { throw 1; } catch { 0; }").takeError(); + EXPECT_THAT(DiagnosticOutput, HasSubstr("error: expected '('")); + EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err))); + + RecoverErr = Interp->Parse("var1 = 424;"); + EXPECT_TRUE(!!RecoverErr); } // Here we test whether the user can mix declarations and statements. The