@@ -734,6 +734,115 @@ TEST(FunctionReflectionTest, LookupConstructors) {
734734 EXPECT_EQ (Cpp::GetFunctionSignature (ctors[3 ]), " MyClass::MyClass(T t)" );
735735}
736736
737+ TEST (FunctionReflectionTest, GetClassTemplatedMethods) {
738+ std::vector<Decl*> Decls;
739+ std::string code = R"(
740+ class MyClass {
741+ public:
742+ MyClass();
743+ void helperMethod();
744+ template<typename T>
745+ MyClass(T);
746+ template<typename U>
747+ void templatedMethod(U param);
748+ template<typename U, typename V>
749+ U templatedMethod(U a, V b);
750+ static void staticFunc();
751+ template<typename T>
752+ static void templatedStaticMethod(T param);
753+ ~MyClass();
754+ };
755+
756+ MyClass::MyClass() {}
757+ void MyClass::helperMethod() {}
758+ template<typename T>
759+ MyClass::MyClass(T t) {}
760+ template<typename U>
761+ void MyClass::templatedMethod(U param) {}
762+ template<typename U, typename V>
763+ U MyClass::templatedMethod(U a, V b) { return a * b; }
764+ void MyClass::staticFunc() {}
765+ template<typename T>
766+ void MyClass::templatedStaticMethod(T param) {}
767+ )" ;
768+
769+ GetAllTopLevelDecls (code, Decls);
770+ std::vector<Cpp::TCppFunction_t> templatedMethods;
771+ Cpp::GetClassTemplatedMethods (" MyClass" , Decls[0 ], templatedMethods);
772+ Cpp::GetClassTemplatedMethods (" templatedMethod" , Decls[0 ], templatedMethods);
773+ Cpp::GetClassTemplatedMethods (" templatedStaticMethod" , Decls[0 ],
774+ templatedMethods);
775+
776+ EXPECT_EQ (templatedMethods.size (), 6 )
777+ << " Templated methods lookup did not retrieve the expected set" ;
778+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[0 ]),
779+ " MyClass::MyClass()" );
780+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[1 ]),
781+ " MyClass::MyClass(T t)" );
782+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[2 ]),
783+ " inline constexpr MyClass::MyClass(const MyClass &)" );
784+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[3 ]),
785+ " void MyClass::templatedMethod(U param)" );
786+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[4 ]),
787+ " U MyClass::templatedMethod(U a, V b)" );
788+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[5 ]),
789+ " void MyClass::templatedStaticMethod(T param)" );
790+ }
791+
792+ TEST (FunctionReflectionTest, GetClassTemplatedMethods_VariadicsAndOthers) {
793+ std::vector<Decl*> Decls;
794+ std::string code = R"(
795+ class MyClass {
796+ public:
797+ template<typename... Args>
798+ void variadicMethod(Args... args);
799+
800+ template<int N>
801+ int fixedMethod();
802+
803+ template<typename T = int>
804+ T defaultMethod(T param);
805+
806+ template<typename U, typename... V>
807+ U variadicMethod(U first, V... rest);
808+
809+ template<typename T, typename... Args>
810+ static void staticVariadic(T t, Args... args);
811+ };
812+
813+ template<typename... Args>
814+ void MyClass::variadicMethod(Args... args) {}
815+ template<int N>
816+ int MyClass::fixedMethod() { return N; }
817+ template<typename T>
818+ T MyClass::defaultMethod(T param) { return param; }
819+ template<typename U, typename... V>
820+ U MyClass::variadicMethod(U first, V... rest) { return first; }
821+ template<typename T, typename... Args>
822+ void MyClass::staticVariadic(T t, Args... args) {}
823+ )" ;
824+
825+ GetAllTopLevelDecls (code, Decls);
826+ std::vector<Cpp::TCppFunction_t> templatedMethods;
827+ Cpp::GetClassTemplatedMethods (" fixedMethod" , Decls[0 ], templatedMethods);
828+ Cpp::GetClassTemplatedMethods (" defaultMethod" , Decls[0 ], templatedMethods);
829+ Cpp::GetClassTemplatedMethods (" variadicMethod" , Decls[0 ], templatedMethods);
830+ Cpp::GetClassTemplatedMethods (" staticVariadic" , Decls[0 ], templatedMethods);
831+
832+ EXPECT_EQ (templatedMethods.size (), 5 )
833+ << " Templated methods lookup did not retrieve the expected set" ;
834+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[0 ]),
835+ " int MyClass::fixedMethod()" );
836+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[1 ]),
837+ " T MyClass::defaultMethod(T param)" );
838+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[2 ]),
839+ " void MyClass::variadicMethod(Args ...args)" );
840+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[3 ]),
841+ " U MyClass::variadicMethod(U first, V ...rest)" );
842+ EXPECT_EQ (Cpp::GetFunctionSignature (templatedMethods[4 ]),
843+ " void MyClass::staticVariadic(T t, Args ...args)" );
844+ }
845+
737846TEST (FunctionReflectionTest, BestOverloadFunctionMatch1) {
738847 std::vector<Decl*> Decls;
739848 std::string code = R"(
0 commit comments