[clang] f2b2490 - [Sema] Mark the referenced destructor during transformation of a `CXXBindTemporaryExpr`

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 8 01:00:30 PST 2022


Author: Argyrios Kyrtzidis
Date: 2022-03-08T01:00:07-08:00
New Revision: f2b24905bfede6bd047a38f5cbae352e6b845428

URL: https://github.com/llvm/llvm-project/commit/f2b24905bfede6bd047a38f5cbae352e6b845428
DIFF: https://github.com/llvm/llvm-project/commit/f2b24905bfede6bd047a38f5cbae352e6b845428.diff

LOG: [Sema] Mark the referenced destructor during transformation of a `CXXBindTemporaryExpr`

Otherwise we will fail to generate the definition of a defaulted destructor,
if the only reference was in a templated temporary.

rdar://89366678

Differential Revision: https://reviews.llvm.org/D120426

Added: 
    clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp

Modified: 
    clang/lib/Sema/TreeTransform.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 0716689d4b626..6676bffb8a47a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12748,6 +12748,9 @@ ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
 template<typename Derived>
 ExprResult
 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+  if (auto *Dtor = E->getTemporary()->getDestructor())
+    SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
+                                   const_cast<CXXDestructorDecl *>(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
index 0000000000000..cbd4950c6af8e
--- /dev/null
+++ b/clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-apple-darwin %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 <typename>
+  void h() {
+    s = {};
+  }
+  void f();
+};
+void E::f() {
+  h<int>();
+}


        


More information about the cfe-commits mailing list