diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -12748,6 +12748,9 @@ template ExprResult TreeTransform::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { + if (auto *Dtor = + const_cast(E->getTemporary()->getDestructor())) + SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Dtor); return getDerived().TransformExpr(E->getSubExpr()); } diff --git a/clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp b/clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - | FileCheck %s + +// CHECK: define linkonce_odr {{.*}} @_ZN3StrD1Ev + +class A { +public: + ~A(); +}; +class Str { + A d; + +public: + ~Str() = default; +}; +class E { + Str s; + template + void h() { + s = {}; + } + void f(); +}; +void E::f() { + h(); +}