Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1011,10 +1011,17 @@ template bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr( const CXXTemporaryObjectExpr *E) { - if (std::optional LocalIndex = allocateLocal(E, /*IsExtended=*/false)) { - return this->visitLocalInitializer(E, *LocalIndex); + if (!this->emitGetPtrLocal(*LocalIndex, E)) + return false; + + if (!this->visitInitializer(E)) + return false; + + if (DiscardResult) + return this->emitPopPtr(E); + return true; } return false; } Index: clang/test/AST/Interp/records.cpp =================================================================== --- clang/test/AST/Interp/records.cpp +++ clang/test/AST/Interp/records.cpp @@ -880,3 +880,13 @@ } } +namespace TemporaryObjectExpr { + struct F { + int a; + constexpr F() : a(12) {} + }; + constexpr int foo(F f) { + return 0; + } + static_assert(foo(F()) == 0, ""); +}