@@ -973,6 +973,55 @@ TYPED_TEST(CppInterOpTest, FunctionReflectionTestInstantiateVariadicFunction) {
973973 " fixedParam, MyClass args, double args)" );
974974}
975975
976+ TYPED_TEST (CppInterOpTest, FunctionReflectionTestBestOverloadFunctionMatch0) {
977+ // make sure templates are not instantiated multiple times
978+ std::vector<Decl*> Decls;
979+ std::string code = R"(
980+ template <typename T1, typename T2 = int>
981+ void Tfn(T1& t1, T2& t2) {}
982+ )" ;
983+ GetAllTopLevelDecls (code, Decls);
984+ EXPECT_EQ (Decls.size (), 1 );
985+
986+ std::vector<Cpp::TCppFunction_t> candidates;
987+ for (auto i : Decls)
988+ candidates.push_back (i);
989+
990+ ASTContext& C = Interp->getCI ()->getASTContext ();
991+
992+ std::vector<Cpp::TemplateArgInfo> args0 = {
993+ C.getLValueReferenceType (C.DoubleTy ).getAsOpaquePtr (),
994+ C.getLValueReferenceType (C.IntTy ).getAsOpaquePtr (),
995+ };
996+
997+ std::vector<Cpp::TemplateArgInfo> explicit_args0;
998+ std::vector<Cpp::TemplateArgInfo> explicit_args1 = {
999+ C.DoubleTy .getAsOpaquePtr ()};
1000+ std::vector<Cpp::TemplateArgInfo> explicit_args2 = {
1001+ C.DoubleTy .getAsOpaquePtr (),
1002+ C.IntTy .getAsOpaquePtr (),
1003+ };
1004+
1005+ Cpp::TCppScope_t fn0 =
1006+ Cpp::BestOverloadFunctionMatch (candidates, explicit_args0, args0);
1007+ EXPECT_TRUE (fn0);
1008+
1009+ Cpp::TCppScope_t fn =
1010+ Cpp::BestOverloadFunctionMatch (candidates, explicit_args1, args0);
1011+ EXPECT_EQ (fn, fn0);
1012+
1013+ fn = Cpp::BestOverloadFunctionMatch (candidates, explicit_args2, args0);
1014+ EXPECT_EQ (fn, fn0);
1015+
1016+ fn = Cpp::InstantiateTemplate (Decls[0 ], explicit_args1.data (),
1017+ explicit_args1.size ());
1018+ EXPECT_EQ (fn, fn0);
1019+
1020+ fn = Cpp::InstantiateTemplate (Decls[0 ], explicit_args2.data (),
1021+ explicit_args2.size ());
1022+ EXPECT_EQ (fn, fn0);
1023+ }
1024+
9761025TYPED_TEST (CppInterOpTest, FunctionReflectionTestBestOverloadFunctionMatch1) {
9771026 std::vector<Decl*> Decls;
9781027 std::string code = R"(
0 commit comments