Skip to content

Commit 0411eb4

Browse files
committed
Add test to check base virtual method call
1 parent a5a21bf commit 0411eb4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,35 @@ 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+
Interp->declare(R"(
580+
struct A {
581+
virtual ~A() {}
582+
virtual int func() {
583+
return 1;
584+
}
585+
};
586+
587+
struct B : public A {
588+
virtual int func() {
589+
return 2;
590+
}
591+
};
592+
)");
593+
594+
auto *St_A = Cpp::GetNamed("A", 0);
595+
auto *St_B = Cpp::GetNamed("B", 0);
596+
597+
auto *BCtorD = Cpp::GetDefaultConstructor(St_B);
598+
auto BCtor = Cpp::MakeFunctionCallable(BCtorD);
599+
void *BObj = nullptr;
600+
BCtor.Invoke(&BObj);
601+
602+
auto *AfuncD = Cpp::GetNamed("func", St_A);
603+
auto Afunc = Cpp::MakeFunctionCallable(AfuncD);
604+
int ret_func;
605+
Afunc.Invoke(&ret_func, {nullptr, 0}, BObj);
606+
EXPECT_EQ(ret_func, 1);
578607
}
579608

580609
TEST(FunctionReflectionTest, GetFunctionCallWrapper) {

0 commit comments

Comments
 (0)