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

Argyrios Kyrtzidis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 23 12:06:09 PST 2022


akyrtzi created this revision.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

rdar://89366678


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120426

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp


Index: clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp
===================================================================
--- /dev/null
+++ 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 <typename>
+  void h() {
+    s = {};
+  }
+  void f();
+};
+void E::f() {
+  h<int>();
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12748,6 +12748,9 @@
 template<typename Derived>
 ExprResult
 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+  SemaRef.MarkFunctionReferenced(
+      E->getBeginLoc(),
+      const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
   return getDerived().TransformExpr(E->getSubExpr());
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120426.410901.patch
Type: text/x-patch
Size: 1087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220223/36c9cabb/attachment.bin>


More information about the cfe-commits mailing list