From 7a7ad5e7bfec63470a282267d97fd0c9f126ed19 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 13 Jun 2025 15:55:25 +0200 Subject: [PATCH 1/3] fix codegen to not cast func if templated this is taken from cling --- lib/CppInterOp/CppInterOp.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index e619750e3..67a5ef6ad 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1987,8 +1987,9 @@ void make_narg_call(const FunctionDecl* FD, const std::string& return_type, bool op_flag = !FD->isOverloadedOperator() || FD->getOverloadedOperator() == clang::OO_Call; - bool ShouldCastFunction = - !isa(FD) && N == FD->getNumParams() && op_flag; + bool ShouldCastFunction = !isa(FD) && + N == FD->getNumParams() && op_flag && + !FD->isTemplateInstantiation(); if (ShouldCastFunction) { callbuf << "("; callbuf << "("; From 6f5559b98efaab7e6a5c1b5e95ceb90472d77a67 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 13 Jun 2025 15:56:22 +0200 Subject: [PATCH 2/3] fix `BestOverloadFunctionMatch` to handle rvalues --- lib/CppInterOp/CppInterOp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 67a5ef6ad..f2d806b45 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1142,7 +1142,7 @@ BestOverloadFunctionMatch(const std::vector& candidates, for (auto i : arg_types) { QualType Type = QualType::getFromOpaquePtr(i.m_Type); ExprValueKind ExprKind = ExprValueKind::VK_PRValue; - if (Type->isReferenceType()) + if (Type->isLValueReferenceType()) ExprKind = ExprValueKind::VK_LValue; new (&Exprs[idx]) OpaqueValueExpr(SourceLocation::getFromRawEncoding(1), From 7c5c9116a60f4bd6529bacdfb77a6a65e41988a2 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 13 Jun 2025 15:56:35 +0200 Subject: [PATCH 3/3] add test --- .../CppInterOp/FunctionReflectionTest.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index a4baee5a5..1ed05bbd2 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -1824,6 +1824,26 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { auto fn_callable = Cpp::MakeFunctionCallable(fn); EXPECT_EQ(fn_callable.getKind(), Cpp::JitCall::kGenericCall); + + Interp->process(R"( + template + bool call_move(T&& t) { + return true; + } + )"); + + unresolved_candidate_methods.clear(); + Cpp::GetClassTemplatedMethods("call_move", Cpp::GetGlobalScope(), + unresolved_candidate_methods); + EXPECT_EQ(unresolved_candidate_methods.size(), 1); + + Cpp::TCppScope_t call_move = Cpp::BestOverloadFunctionMatch( + unresolved_candidate_methods, {}, + {Cpp::GetReferencedType(Cpp::GetType("int"), true)}); + EXPECT_TRUE(call_move); + + auto call_move_callable = Cpp::MakeFunctionCallable(call_move); + EXPECT_EQ(call_move_callable.getKind(), Cpp::JitCall::kGenericCall); } TEST(FunctionReflectionTest, IsConstMethod) {