Bug 102042 - specialization after instantiation error possibly rooted from mis-calculating template function signature of parameter of array of template function
Summary: specialization after instantiation error possibly rooted from mis-calculating...
Status: RESOLVED DUPLICATE of bug 102033
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2021-08-24 13:57 UTC by qingzhe huang
Modified: 2021-08-24 15:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description qingzhe huang 2021-08-24 13:57:08 UTC
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]){}
      |                                     ^
Comment 1 qingzhe huang 2021-08-24 14:41:03 UTC
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]){}
      |
Comment 2 qingzhe huang 2021-08-24 15:16:01 UTC
Just tested with my fix, it can be fixed with my suggested patch in PR102033.
Comment 3 Jonathan Wakely 2021-08-24 15:29:45 UTC
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 ***