From a97f37e62dc12c81e3eb1f65829c296e155051c0 Mon Sep 17 00:00:00 2001 From: Baidyanath Kundu Date: Wed, 19 Jul 2023 19:47:56 +0530 Subject: [PATCH] Add test to check base virtual method call --- .../CppInterOp/FunctionReflectionTest.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 5b76e1001..090b109b1 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -849,6 +849,35 @@ TEST(FunctionReflectionTest, JitCallAdvanced) { EXPECT_TRUE(object) << "Failed to call the ctor."; // Building a wrapper with a typedef decl must be possible. Cpp::Destruct(object, Decls[1]); + + Interp->declare(R"( + struct A { + virtual ~A() {} + virtual int func() { + return 1; + } + }; + + struct B : public A { + virtual int func() { + return 2; + } + }; + )"); + + auto *St_A = Cpp::GetNamed("A", 0); + auto *St_B = Cpp::GetNamed("B", 0); + + auto *BCtorD = Cpp::GetDefaultConstructor(St_B); + auto BCtor = Cpp::MakeFunctionCallable(BCtorD); + void *BObj = nullptr; + BCtor.Invoke(&BObj); + + auto *AfuncD = Cpp::GetNamed("func", St_A); + auto Afunc = Cpp::MakeFunctionCallable(AfuncD); + int ret_func; + Afunc.Invoke(&ret_func, {nullptr, 0}, BObj); + EXPECT_EQ(ret_func, 1); }