https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82657
Bug ID: 82657 Summary: when using a template function pointer as a non-type template parameters, the template function will not be defined in some situation Product: gcc Version: new-ra Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: niqiuha at gmail dot com Target Milestone: --- typedef bool(*func)(int); //template<typename T = int> //class TC1{ // public: // static bool test_func(T t){ // return true; // } //}; template<typename T=int> bool test_func(T){ return true; } template< func f = &test_func> class TC2{ public: TC2(){ //uncomment the line below ,compile will pass //test_func(3); f(3); } }; template<typename T = char> class TC3{ public: TC2<> mc; TC3() = default; }; int main(){ TC3<> tc3; //uncomment the line below ,compile will pass //TC2<> mc; } This piece of code compile ok on clang 7.3.0 , But fail to compile ( https://www.ideone.com/Dd092k ) on gcc 4.8.2, 5.2.0, 6.3 . Gcc error information : /tmp/ccW3jgBm.o: In function `TC2<&(bool test_func<int>(int))>::TC2()': tempdef.cpp:(.text._ZN3TC2IXadL_Z9test_funcIiEbT_EEEC2Ev[_ZN3TC2IXadL_Z9test_funcIiEbT_EEEC5Ev]+0x12): undefined reference to `bool test_func<int>(int)' collect2: error: ld returned 1 exit status I did some test , and found: 1. uncomment either line in code with special introduction will make this code pass compile on gcc 2. change test_func from template function to static function of template class, the error is same .