[PATCH] D82284: [AST][RecoveryAST] Preseve invalid return stmt, and suppress the diagnostics for missing return stmt in constexpr func.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 30 00:27:10 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc21928285430: [AST][RecoveryAST] Preseve more invalid return stmt. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D82284/new/
https://reviews.llvm.org/D82284
Files:
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/constant-expression-cxx11.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/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1807,11 +1807,10 @@
}
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 {
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3629,7 +3629,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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82284.308276.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201130/a947f2ca/attachment-0001.bin>
More information about the cfe-commits
mailing list