Skip to content

Commit

Permalink
[Sema] Mark the referenced destructor during transformation of a `CXX…
Browse files Browse the repository at this point in the history
…BindTemporaryExpr`

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
  • Loading branch information
akyrtzi committed Mar 8, 2022
1 parent 802fc8c commit f2b2490
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Expand Up @@ -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());
}

Expand Down
25 changes: 25 additions & 0 deletions 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>();
}

0 comments on commit f2b2490

Please sign in to comment.