Skip to content

Commit 0fc3cc8

Browse files
committed
Add test to check if typedefs are being unnecessarily resolved.
1 parent a5a21bf commit 0fc3cc8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

unittests/CppInterOp/FunctionReflectionTest.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,39 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
575575
EXPECT_TRUE(object) << "Failed to call the ctor.";
576576
// Building a wrapper with a typedef decl must be possible.
577577
Cpp::Destruct(object, Decls[1]);
578+
579+
// Test to check if typedefs are unnecessarily resolved during the creation
580+
// of the wrapper
581+
Interp->process(R"(
582+
class TDT {
583+
private:
584+
class PC {
585+
public:
586+
PC(int i) : m_val(i) {}
587+
int m_val;
588+
};
589+
590+
public:
591+
typedef PC PP;
592+
PP f() { return PC(42); }
593+
};
594+
)");
595+
596+
clang::NamedDecl *ClassTDT = (clang::NamedDecl*) Cpp::GetNamed("TDT");
597+
auto *CtorTDT =
598+
(clang::CXXConstructorDecl*) Cpp::GetDefaultConstructor(ClassTDT);
599+
auto FCI_CtorTDT = Cpp::MakeFunctionCallable(CtorTDT);
600+
void* objectTDT = nullptr;
601+
FCI_CtorTDT.Invoke((void*)&objectTDT);
602+
EXPECT_TRUE(objectTDT != nullptr);
603+
clang::NamedDecl *TDT_f = (clang::NamedDecl*) Cpp::GetNamed("f", ClassTDT);
604+
auto FCI_TDT_f = Cpp::MakeFunctionCallable(TDT_f);
605+
void* objectTDT_PP = nullptr;
606+
FCI_TDT_f.Invoke((void*) &objectTDT_PP, {}, objectTDT);
607+
EXPECT_TRUE(objectTDT_PP != nullptr);
608+
std::stringstream ss_mval;
609+
ss_mval << "(" << objectTDT_PP << ")->mval";
610+
EXPECT_EQ(Cpp::Evaluate(ss_mval.str().c_str()), 42);
578611
}
579612

580613
TEST(FunctionReflectionTest, GetFunctionCallWrapper) {

0 commit comments

Comments
 (0)