hokein created this revision. hokein added a reviewer: sammccall. Herald added a project: clang.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D82284 Files: clang/lib/Sema/SemaStmt.cpp clang/test/AST/ast-dump-recovery.cpp clang/test/SemaCXX/constant-expression-cxx11.cpp clang/test/SemaCXX/lambda-expressions.cpp clang/test/SemaCXX/typo-correction-crash.cpp Index: clang/test/SemaCXX/typo-correction-crash.cpp =================================================================== --- clang/test/SemaCXX/typo-correction-crash.cpp +++ clang/test/SemaCXX/typo-correction-crash.cpp @@ -16,7 +16,8 @@ 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"); Index: clang/test/SemaCXX/lambda-expressions.cpp =================================================================== --- clang/test/SemaCXX/lambda-expressions.cpp +++ clang/test/SemaCXX/lambda-expressions.cpp @@ -519,7 +519,7 @@ auto blk = [](bool b) { if (b) return undeclared_error; // expected-error {{use of undeclared identifier}} - return 0; + return 0; // expected-error {{cannot initialize return object of type 'auto' with an rvalue of type 'int'}} }; } } Index: clang/test/SemaCXX/constant-expression-cxx11.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx11.cpp +++ clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1794,11 +1794,11 @@ } namespace AfterError { - // FIXME: Suppress the 'no return statements' diagnostic if the body is invalid. - constexpr int error() { // expected-error {{no return statement}} - return foobar; // expected-error {{undeclared identifier}} + constexpr int error() { // expected-error {{constexpr function never produces a constant expression}} + return foobar; // expected-error {{undeclared identifier}} expected-note 2{{subexpression not valid in a constant expression}} } - constexpr int k = error(); + constexpr int k = error(); // expected-error {{constexpr variable 'k' must be initialized by a constant expression}} \ + // expected-note {{in call to 'error()'}} } namespace std { Index: clang/test/AST/ast-dump-recovery.cpp =================================================================== --- clang/test/AST/ast-dump-recovery.cpp +++ clang/test/AST/ast-dump-recovery.cpp @@ -125,6 +125,12 @@ // CHECK-NEXT:| `-UnresolvedLookupExpr {{.*}} 'invalid' struct alignas(invalid()) Aligned {}; +void InvalidReturn() { + // CHECK: `-ReturnStmt {{.*}} + // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors + return undef; +} + void InvalidInitalizer(int x) { struct Bar { Bar(); }; // CHECK: `-VarDecl {{.*}} a1 'Bar' Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -3586,7 +3586,8 @@ 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());
Index: clang/test/SemaCXX/typo-correction-crash.cpp =================================================================== --- clang/test/SemaCXX/typo-correction-crash.cpp +++ clang/test/SemaCXX/typo-correction-crash.cpp @@ -16,7 +16,8 @@ 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"); Index: clang/test/SemaCXX/lambda-expressions.cpp =================================================================== --- clang/test/SemaCXX/lambda-expressions.cpp +++ clang/test/SemaCXX/lambda-expressions.cpp @@ -519,7 +519,7 @@ auto blk = [](bool b) { if (b) return undeclared_error; // expected-error {{use of undeclared identifier}} - return 0; + return 0; // expected-error {{cannot initialize return object of type 'auto' with an rvalue of type 'int'}} }; } } Index: clang/test/SemaCXX/constant-expression-cxx11.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx11.cpp +++ clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1794,11 +1794,11 @@ } namespace AfterError { - // FIXME: Suppress the 'no return statements' diagnostic if the body is invalid. - constexpr int error() { // expected-error {{no return statement}} - return foobar; // expected-error {{undeclared identifier}} + constexpr int error() { // expected-error {{constexpr function never produces a constant expression}} + return foobar; // expected-error {{undeclared identifier}} expected-note 2{{subexpression not valid in a constant expression}} } - constexpr int k = error(); + constexpr int k = error(); // expected-error {{constexpr variable 'k' must be initialized by a constant expression}} \ + // expected-note {{in call to 'error()'}} } namespace std { Index: clang/test/AST/ast-dump-recovery.cpp =================================================================== --- clang/test/AST/ast-dump-recovery.cpp +++ clang/test/AST/ast-dump-recovery.cpp @@ -125,6 +125,12 @@ // CHECK-NEXT:| `-UnresolvedLookupExpr {{.*}} 'invalid' struct alignas(invalid()) Aligned {}; +void InvalidReturn() { + // CHECK: `-ReturnStmt {{.*}} + // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors + return undef; +} + void InvalidInitalizer(int x) { struct Bar { Bar(); }; // CHECK: `-VarDecl {{.*}} a1 'Bar' Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -3586,7 +3586,8 @@ 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());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits