diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index b80f66fe6..807341f12 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), @@ -1993,8 +1993,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 << "("; diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 38d6e5462..a7779201e 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -1836,6 +1836,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); + // instantiation in host, no template function body Interp->process("template T instantiation_in_host();");