Author: Haojian Wu Date: 2020-11-30T09:26:41+01:00 New Revision: c21928285430cc25905f774a89cb948867ae55b6
URL: https://github.com/llvm/llvm-project/commit/c21928285430cc25905f774a89cb948867ae55b6 DIFF: https://github.com/llvm/llvm-project/commit/c21928285430cc25905f774a89cb948867ae55b6.diff LOG: [AST][RecoveryAST] Preseve more invalid return stmt. suppress the diagnostics for missing return stmt in constexpr func. Differential Revision: https://reviews.llvm.org/D82284 Added: Modified: clang/lib/Sema/SemaStmt.cpp clang/test/SemaCXX/constant-expression-cxx11.cpp clang/test/SemaCXX/typo-correction-crash.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index f5bf889b3878..d89dfaf78a9c 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3629,7 +3629,8 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope) { // Correct typos, in case the containing function returns 'auto' and // RetValExp should determine the deduced type. - ExprResult RetVal = CorrectDelayedTyposInExpr(RetValExp); + ExprResult RetVal = CorrectDelayedTyposInExpr( + RetValExp, nullptr, /*RecoverUncorrectedTypos=*/true); if (RetVal.isInvalid()) return StmtError(); StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get()); diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 8b80f5438d8e..67c5e78b8791 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1807,11 +1807,10 @@ namespace PR15884 { } namespace AfterError { - // FIXME: Suppress the 'no return statements' diagnostic if the body is invalid. - constexpr int error() { // expected-error {{no return statement}} + constexpr int error() { return foobar; // expected-error {{undeclared identifier}} } - constexpr int k = error(); + constexpr int k = error(); // expected-error {{constexpr variable 'k' must be initialized by a constant expression}} } namespace std { diff --git a/clang/test/SemaCXX/typo-correction-crash.cpp b/clang/test/SemaCXX/typo-correction-crash.cpp index 10c0c11aaa6b..49ea4c1bf16c 100644 --- a/clang/test/SemaCXX/typo-correction-crash.cpp +++ b/clang/test/SemaCXX/typo-correction-crash.cpp @@ -16,7 +16,8 @@ template <class A> struct is_same<A,A> { static constexpr bool value = true; }; auto L1 = [] { return s; }; // expected-error {{use of undeclared identifier 's'}} using T1 = decltype(L1()); -static_assert(is_same<T1, void>::value, "Return statement should be discarded"); +// FIXME: Suppress the 'undeclared identifier T1' diagnostic, the UsingDecl T1 is discarded because of an invalid L1(). +static_assert(is_same<T1, void>::value, "Return statement should be discarded"); // expected-error {{use of undeclared identifier 'T1'}} auto L2 = [] { return tes; }; // expected-error {{use of undeclared identifier 'tes'; did you mean 'test'?}} using T2 = decltype(L2()); static_assert(is_same<T2, int>::value, "Return statement was corrected"); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits