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