From 4c98da2cadfb23f6d4070db9136d8dc0a379bcc1 Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Tue, 8 Jul 2025 06:00:52 +0200 Subject: [clang][bytecode] Create a temporary for discarded CXXBindTemporaryExprs (#147303) So we run the destructor. --- clang/lib/AST/ByteCode/Compiler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index d1c93e4..51c234d 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2886,7 +2886,20 @@ bool Compiler::VisitMaterializeTemporaryExpr( template bool Compiler::VisitCXXBindTemporaryExpr( const CXXBindTemporaryExpr *E) { - return this->delegate(E->getSubExpr()); + const Expr *SubExpr = E->getSubExpr(); + + if (Initializing) + return this->delegate(SubExpr); + + // Make sure we create a temporary even if we're discarding, since that will + // make sure we will also call the destructor. + + if (!this->visit(SubExpr)) + return false; + + if (DiscardResult) + return this->emitPopPtr(E); + return true; } template -- cgit v1.1