Skip to content

Commit f01e984

Browse files
sudo-pandavgvassilev
authored andcommitted
Add test to check if typedefs are being unnecessarily resolved.
1 parent cff06c7 commit f01e984

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
@@ -849,6 +849,39 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
849849
EXPECT_TRUE(object) << "Failed to call the ctor.";
850850
// Building a wrapper with a typedef decl must be possible.
851851
Cpp::Destruct(object, Decls[1]);
852+
853+
// Test to check if typedefs are unnecessarily resolved during the creation
854+
// of the wrapper
855+
Interp->process(R"(
856+
class TDT {
857+
private:
858+
class PC {
859+
public:
860+
PC(int i) : m_val(i) {}
861+
int m_val;
862+
};
863+
864+
public:
865+
typedef PC PP;
866+
PP f() { return PC(42); }
867+
};
868+
)");
869+
870+
clang::NamedDecl *ClassTDT = (clang::NamedDecl*) Cpp::GetNamed("TDT");
871+
auto *CtorTDT =
872+
(clang::CXXConstructorDecl*) Cpp::GetDefaultConstructor(ClassTDT);
873+
auto FCI_CtorTDT = Cpp::MakeFunctionCallable(CtorTDT);
874+
void* objectTDT = nullptr;
875+
FCI_CtorTDT.Invoke((void*)&objectTDT);
876+
EXPECT_TRUE(objectTDT != nullptr);
877+
clang::NamedDecl *TDT_f = (clang::NamedDecl*) Cpp::GetNamed("f", ClassTDT);
878+
auto FCI_TDT_f = Cpp::MakeFunctionCallable(TDT_f);
879+
void* objectTDT_PP = nullptr;
880+
FCI_TDT_f.Invoke((void*) &objectTDT_PP, {}, objectTDT);
881+
EXPECT_TRUE(objectTDT_PP != nullptr);
882+
std::stringstream ss_mval;
883+
ss_mval << "(" << objectTDT_PP << ")->mval";
884+
EXPECT_EQ(Cpp::Evaluate(ss_mval.str().c_str()), 42);
852885
}
853886

854887

0 commit comments

Comments
 (0)