llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> Also, increase the EvalID in isPotentialConstantExpr(), since this is its own evaluation. --- Full diff: https://github.com/llvm/llvm-project/pull/140039.diff 3 Files Affected: - (modified) clang/lib/AST/ByteCode/Context.cpp (+1) - (modified) clang/lib/AST/ByteCode/Interp.cpp (+2) - (modified) clang/test/AST/ByteCode/cxx20.cpp (+10) ``````````diff diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index dae94fc9829c7..c70a5259b77e2 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -37,6 +37,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) { Compiler<ByteCodeEmitter>(*this, *P).compileFunc( FD, const_cast<Function *>(Func)); + ++EvalID; // And run it. if (!Run(Parent, Func)) return false; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index bc860185fea21..fbe04fe3231dd 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1373,6 +1373,8 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { if (!CheckLive(S, OpPC, Ptr, AK_Destroy)) return false; + if (!CheckTemporary(S, OpPC, Ptr, AK_Destroy)) + return false; // Can't call a dtor on a global variable. if (Ptr.block()->isStatic()) { diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp index 8fb19fcfcd3fe..5f62a5648bab7 100644 --- a/clang/test/AST/ByteCode/cxx20.cpp +++ b/clang/test/AST/ByteCode/cxx20.cpp @@ -997,3 +997,13 @@ namespace NastyChar { template <ToNastyChar t> constexpr auto to_nasty_char() { return t; } constexpr auto result = to_nasty_char<"12345">(); } + +namespace TempDtor { + struct A { + int n; + }; + constexpr A &&a_ref = A(); // both-note {{temporary created here}} + constexpr void destroy_extern_2() { // both-error {{never produces a constant expression}} + a_ref.~A(); // both-note {{destruction of temporary is not allowed in a constant expression outside the expression that created the temporary}} + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/140039 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits