This revision was automatically updated to reflect the committed changes. Closed by commit rGca50f09db9f8: [clang] fix error detection in consteval calls (authored by Tyker). Herald added a project: clang. Herald added a subscriber: cfe-commits.
Changed prior to commit: https://reviews.llvm.org/D74418?vs=243892&id=246810#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D74418/new/ https://reviews.llvm.org/D74418 Files: clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/cxx2a-consteval.cpp Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -309,6 +309,14 @@ namespace alloc { +consteval int f() { + int *A = new int(0); +// expected-note@-1+ {{allocation performed here was not deallocated}} + return *A; +} + +int i1 = f(); // expected-error {{is not a constant expression}} + struct A { int* p = new int(42); // expected-note@-1+ {{heap allocation performed here}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -15368,8 +15368,9 @@ Expr::EvalResult Eval; Eval.Diag = &Notes; ConstantExpr *CE = Candidate.getPointer(); - if (!CE->EvaluateAsConstantExpr(Eval, Expr::EvaluateForCodeGen, - SemaRef.getASTContext(), true)) { + bool Result = CE->EvaluateAsConstantExpr(Eval, Expr::EvaluateForCodeGen, + SemaRef.getASTContext(), true); + if (!Result || !Notes.empty()) { Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); FunctionDecl *FD = nullptr; if (auto *Call = dyn_cast<CallExpr>(InnerExpr))
Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -309,6 +309,14 @@ namespace alloc { +consteval int f() { + int *A = new int(0); +// expected-note@-1+ {{allocation performed here was not deallocated}} + return *A; +} + +int i1 = f(); // expected-error {{is not a constant expression}} + struct A { int* p = new int(42); // expected-note@-1+ {{heap allocation performed here}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -15368,8 +15368,9 @@ Expr::EvalResult Eval; Eval.Diag = &Notes; ConstantExpr *CE = Candidate.getPointer(); - if (!CE->EvaluateAsConstantExpr(Eval, Expr::EvaluateForCodeGen, - SemaRef.getASTContext(), true)) { + bool Result = CE->EvaluateAsConstantExpr(Eval, Expr::EvaluateForCodeGen, + SemaRef.getASTContext(), true); + if (!Result || !Notes.empty()) { Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); FunctionDecl *FD = nullptr; if (auto *Call = dyn_cast<CallExpr>(InnerExpr))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits