I suspect this is from similar root cause of PR101402, PR102033, PR102034 etc. when incorrectly dropping top-level cv-qualifier during calculating template function declarator of which parameter is an array of template function pointer. Clearly from "#2" of static assert, GCC already gets correct specialization "g<1,int>" signature, still the last statement of specialization declaration causes error with very strange error message. clang(https://www.godbolt.org/z/5eM5b4GjG) accepts. MSVC++(https://www.godbolt.org/z/3x9dvsfTh) stumbles like GCC, but a better clear clue. #include<type_traits> template<unsigned int N, class T> void f(const T[N]){} template<unsigned int N, class T> using fPtr=decltype(f<N,T>)*; template<unsigned int N, class T> fPtr<N,T> af[N]={&f<N,T>}; // even without initialization,error still is template<unsigned int N, class T> void g(const decltype(af<N,T>)&){} static_assert(std::is_same<decltype(af<1,int>), fPtr<1,int>[1] >::value, "af is correct"); // #1 static_assert(std::is_same<decltype(g<1,int>), void(fPtr<1,int>const(&)[1])>::value, "fun"); // #2 template<> void g<1,int>(fPtr<1,int>const(&)[1]){} GCC gives very misleading error message: error: specialization of 'void g(decltype (af<N, T>)&) [with unsigned int N = 1; T = int; decltype (af<N, T>) = void (* [1])(const int*)]' after instantiation 21 | void g<1,int>(fPtr<1,int>const(&)[1]){} | ^
Slightly change the prototype of "g" from reference to pointer, you have exact same error. (please note #0 changes to pointer type) #include<type_traits> template<unsigned int N, class T> void f(const T[N]){} template<unsigned int N, class T> using fPtr=decltype(f<N,T>)*; template<unsigned int N, class T> fPtr<N,T> af[N]={&f<N,T>}; template<unsigned int N, class T> void g(const decltype(af<N,T>)*){} // #0 static_assert(std::is_same<decltype(g<1,int>), void(const fPtr<1,int>(*)[1])>::value, "fun"); // #2 template<> void g<1,int>(const fPtr<1,int>(*)[1]){} error: specialization of 'void g(decltype (af<N, T>)*) [with unsigned int N = 1; T = int; decltype (af<N, T>) = void (* [1])(const int*)]' after instantiation 24 | void g<1,int>(const fPtr<1,int>(*)[1]){} |
Just tested with my fix, it can be fixed with my suggested patch in PR102033.
Another dup then. Your patch should include this as a testcase too (and should be submitted to the mailing list). *** This bug has been marked as a duplicate of bug 102033 ***