diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index d4b1578ea..34403341a 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -1004,8 +1004,9 @@ namespace Cpp { continue; #endif - // FIXME : first score based on the type similarity before forcing + // TODO(aaronj0) : first score based on the type similarity before forcing // instantiation. + TCppFunction_t instantiated = InstantiateTemplate(candidate, arg_types.data(), arg_types.size()); if (instantiated) @@ -1018,6 +1019,19 @@ namespace Cpp { explicit_types.size()); if (instantiated) return instantiated; + + // join explicit and arg_types + std::vector total_arg_set; + total_arg_set.reserve(explicit_types.size() + arg_types.size()); + total_arg_set.insert(total_arg_set.end(), explicit_types.begin(), + explicit_types.end()); + total_arg_set.insert(total_arg_set.end(), arg_types.begin(), + arg_types.end()); + + instantiated = InstantiateTemplate(candidate, total_arg_set.data(), + total_arg_set.size()); + if (instantiated) + return instantiated; } return nullptr; } diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 5b76e1001..c3c643b8d 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -597,6 +597,7 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) { template long get_size(A&); template long get_size(); template long get_size(A a, B b); + template long add_size(float a); }; template @@ -609,6 +610,11 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) { return sizeof(A) + 1; } + template + long MyTemplatedMethodClass::add_size(float a) { + return sizeof(A) + long(a); + } + template long MyTemplatedMethodClass::get_size(A a, B b) { return sizeof(A) + sizeof(B); @@ -626,14 +632,15 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) { std::vector args0; std::vector args1 = {C.IntTy.getAsOpaquePtr()}; std::vector args2 = {C.CharTy.getAsOpaquePtr(), C.FloatTy.getAsOpaquePtr()}; + std::vector args3 = {C.FloatTy.getAsOpaquePtr()}; std::vector explicit_args0; std::vector explicit_args1 = {C.IntTy.getAsOpaquePtr()}; - Cpp::TCppFunction_t func1 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args0, args1); Cpp::TCppFunction_t func2 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args1, args0); Cpp::TCppFunction_t func3 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args0, args2); + Cpp::TCppFunction_t func4 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args1, args3); EXPECT_EQ(Cpp::GetFunctionSignature(func1), "template<> long MyTemplatedMethodClass::get_size(int &)"); @@ -641,6 +648,8 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) { "template<> long MyTemplatedMethodClass::get_size()"); EXPECT_EQ(Cpp::GetFunctionSignature(func3), "template<> long MyTemplatedMethodClass::get_size(char a, float b)"); + EXPECT_EQ(Cpp::GetFunctionSignature(func4), + "template<> long MyTemplatedMethodClass::get_size(float &)"); } TEST(FunctionReflectionTest, IsPublicMethod) {