@@ -589,6 +589,60 @@ TEST(FunctionReflectionTest, InstantiateTemplateMethod) {
589589 EXPECT_TRUE (TA1.getAsType ()->isIntegerType ());
590590}
591591
592+ TEST (FunctionReflectionTest, BestTemplateFunctionMatch) {
593+ std::vector<Decl*> Decls;
594+ std::string code = R"(
595+ class MyTemplatedMethodClass {
596+ public:
597+ template<class A> long get_size(A&);
598+ template<class A> long get_size();
599+ template<class A, class B> long get_size(A a, B b);
600+ };
601+
602+ template<class A>
603+ long MyTemplatedMethodClass::get_size(A&) {
604+ return sizeof(A);
605+ }
606+
607+ template<class A>
608+ long MyTemplatedMethodClass::get_size() {
609+ return sizeof(A) + 1;
610+ }
611+
612+ template<class A, class B>
613+ long MyTemplatedMethodClass::get_size(A a, B b) {
614+ return sizeof(A) + sizeof(B);
615+ }
616+ )" ;
617+
618+ GetAllTopLevelDecls (code, Decls);
619+ std::vector<Cpp::TCppFunction_t> candidates;
620+
621+ for (auto decl : Decls)
622+ if (Cpp::IsTemplatedFunction (decl)) candidates.push_back ((Cpp::TCppFunction_t)decl);
623+
624+ ASTContext& C = Interp->getCI ()->getASTContext ();
625+
626+ std::vector<Cpp::TemplateArgInfo> args0;
627+ std::vector<Cpp::TemplateArgInfo> args1 = {C.IntTy .getAsOpaquePtr ()};
628+ std::vector<Cpp::TemplateArgInfo> args2 = {C.CharTy .getAsOpaquePtr (), C.FloatTy .getAsOpaquePtr ()};
629+
630+ std::vector<Cpp::TemplateArgInfo> explicit_args0;
631+ std::vector<Cpp::TemplateArgInfo> explicit_args1 = {C.IntTy .getAsOpaquePtr ()};
632+
633+
634+ Cpp::TCppFunction_t func1 = Cpp::BestTemplateFunctionMatch (candidates, explicit_args0, args1);
635+ Cpp::TCppFunction_t func2 = Cpp::BestTemplateFunctionMatch (candidates, explicit_args1, args0);
636+ Cpp::TCppFunction_t func3 = Cpp::BestTemplateFunctionMatch (candidates, explicit_args0, args2);
637+
638+ EXPECT_EQ (Cpp::GetFunctionSignature (func1),
639+ " template<> long MyTemplatedMethodClass::get_size<int>(int &)" );
640+ EXPECT_EQ (Cpp::GetFunctionSignature (func2),
641+ " template<> long MyTemplatedMethodClass::get_size<int>()" );
642+ EXPECT_EQ (Cpp::GetFunctionSignature (func3),
643+ " template<> long MyTemplatedMethodClass::get_size<char, float>(char a, float b)" );
644+ }
645+
592646TEST (FunctionReflectionTest, IsPublicMethod) {
593647 std::vector<Decl *> Decls, SubDecls;
594648 std::string code = R"(
0 commit comments