Skip to content

Commit a97f37e

Browse files
sudo-pandavgvassilev
authored andcommitted
Add test to check base virtual method call
1 parent cff06c7 commit a97f37e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

unittests/CppInterOp/FunctionReflectionTest.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,35 @@ 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+
Interp->declare(R"(
854+
struct A {
855+
virtual ~A() {}
856+
virtual int func() {
857+
return 1;
858+
}
859+
};
860+
861+
struct B : public A {
862+
virtual int func() {
863+
return 2;
864+
}
865+
};
866+
)");
867+
868+
auto *St_A = Cpp::GetNamed("A", 0);
869+
auto *St_B = Cpp::GetNamed("B", 0);
870+
871+
auto *BCtorD = Cpp::GetDefaultConstructor(St_B);
872+
auto BCtor = Cpp::MakeFunctionCallable(BCtorD);
873+
void *BObj = nullptr;
874+
BCtor.Invoke(&BObj);
875+
876+
auto *AfuncD = Cpp::GetNamed("func", St_A);
877+
auto Afunc = Cpp::MakeFunctionCallable(AfuncD);
878+
int ret_func;
879+
Afunc.Invoke(&ret_func, {nullptr, 0}, BObj);
880+
EXPECT_EQ(ret_func, 1);
852881
}
853882

854883

0 commit comments

Comments
 (0)