From e98abc3ea0796a5d78eb48f2ee9b3019e8133562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sun, 18 Feb 2024 18:04:27 +0100 Subject: [PATCH] [clang][Interp] Emit dtors when ignoring CXXConstructExprs The comment says we should emit destructors, but we didn't. --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 2 ++ clang/test/AST/Interp/records.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e8b0fffd5ee34d2..a778c300fc33a09 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1848,6 +1848,8 @@ bool ByteCodeExprGen::VisitCXXConstructExpr( // Immediately call the destructor if we have to. if (DiscardResult) { + if (!this->emitRecordDestruction(getRecord(E->getType()))) + return false; if (!this->emitPopPtr(E)) return false; } diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 62f1f1d6e426c3d..7cc5987e0a958f1 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -335,9 +335,9 @@ namespace InitializerTemporaries { }; constexpr int f() { - S{}; // ref-note {{in call to 'S{}.~S()'}} - /// FIXME: Wrong source location below. - return 12; // expected-note {{in call to '&S{}->~S()'}} + S{}; // ref-note {{in call to 'S{}.~S()'}} \ + // expected-note {{in call to '&S{}->~S()'}} + return 12; } static_assert(f() == 12); // both-error {{not an integral constant expression}} \ // both-note {{in call to 'f()'}} @@ -604,9 +604,9 @@ namespace Destructors { } }; constexpr int testS() { - S{}; // ref-note {{in call to 'S{}.~S()'}} - return 1; // expected-note {{in call to '&S{}->~S()'}} - // FIXME: ^ Wrong line + S{}; // ref-note {{in call to 'S{}.~S()'}} \ + // expected-note {{in call to '&S{}->~S()'}} + return 1; } static_assert(testS() == 1); // both-error {{not an integral constant expression}} \ // both-note {{in call to 'testS()'}}