Skip to content

Commit 26c3946

Browse files
committed
Force definition of implicit members to get the destructor.
1 parent aac21a1 commit 26c3946

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace Cpp {
208208
TCppFunction_t GetDefaultConstructor(TCppSema_t sema, TCppScope_t scope);
209209

210210
///\returns the class destructor.
211-
TCppFunction_t GetDestructor(TCppScope_t scope);
211+
TCppFunction_t GetDestructor(TCppSema_t sema, TCppScope_t scope);
212212

213213
std::vector<TCppFunction_t> GetFunctionsUsingName(TCppSema_t sema,
214214
TCppScope_t scope,

lib/Interpreter/CppInterOp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,12 @@ namespace Cpp {
676676
return S->LookupDefaultConstructor(CXXRD);
677677
}
678678

679-
TCppFunction_t GetDestructor(TCppScope_t scope) {
679+
TCppFunction_t GetDestructor(TCppSema_t sema, TCppScope_t scope) {
680680
auto *D = (clang::Decl *) scope;
681681

682682
if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) {
683+
clang::Sema *S = (clang::Sema *)sema;
684+
S->ForceDeclarationOfImplicitMembers(CXXRD);
683685
return CXXRD->getDestructor();
684686
}
685687

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ TEST(FunctionReflectionTest, GetDestructor) {
165165
)";
166166

167167
GetAllTopLevelDecls(code, Decls);
168-
EXPECT_FALSE(Cpp::GetDestructor(Decls[0]));
169-
EXPECT_TRUE(Cpp::GetDestructor(Decls[1]));
168+
Sema *S = &Interp->getCI()->getSema();
169+
170+
EXPECT_TRUE(Cpp::GetDestructor(S, Decls[0]));
171+
EXPECT_TRUE(Cpp::GetDestructor(S, Decls[1]));
172+
auto DeletedDtor = Cpp::GetDestructor(S, Decls[2]);
173+
EXPECT_TRUE(DeletedDtor);
174+
EXPECT_TRUE(Cpp::IsFunctionDeleted(DeletedDtor));
170175
}
171176

172177
TEST(FunctionReflectionTest, GetFunctionsUsingName) {
@@ -661,7 +666,7 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
661666
EXPECT_EQ(output, "Default Ctor Called\n");
662667
EXPECT_TRUE(object != nullptr);
663668

664-
auto *DtorD = (clang::CXXConstructorDecl *)Cpp::GetDestructor(ClassC);
669+
auto *DtorD = (clang::CXXDestructorDecl *)Cpp::GetDestructor(S, ClassC);
665670
auto FCI_Dtor =
666671
Cpp::MakeFunctionCallable((Cpp::TInterp_t)Interp.get(), DtorD);
667672
testing::internal::CaptureStdout();

0 commit comments

Comments
 (0)