Bug 94501 - arrays are not decaying to pointers in variadic function template for conversion to a function pointer
Summary: arrays are not decaying to pointers in variadic function template for convers...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 24666
  Show dependency treegraph
 
Reported: 2020-04-06 13:11 UTC by Patrick Palka
Modified: 2021-09-05 11:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Palka 2020-04-06 13:11:53 UTC
$ cat testcase.C
template<typename... Ts>
void foo(Ts...);

int main()
{
  void (*f)(int*) = foo<int[]>;
}
$ g++ -std=c++11 testcase.C
testcase.C: In function ‘int main()’:
testcase.C:6:21: error: no matches converting function ‘foo’ to type ‘void (*)(int*)’
    6 |   void (*f)(int*) = foo<int[]>;
      |                     ^~~~~~~~~~
testcase.C:2:6: note: candidate is: ‘template<class ... Ts> void foo(Ts ...)’
    2 | void foo(Ts...);
      |      ^~~


But if we replace the template parameter pack Ts with an ordinary template parameter T then the testcase compiles successfully.  The fact that we perform array-to-pointer decaying of "int[]" after substituting into the function parameter pack seems to be relevant here.
Comment 1 Andrew Pinski 2021-08-23 21:12:16 UTC
Confirmed.
Comment 2 qingzhe huang 2021-09-05 11:27:13 UTC
I believe this case of no specialization matching error is related with this bug(clang passed, MSVC++ failed like GCC https://godbolt.org/z/KTahxj868). 
Possibly it is a duplicate case. However, I can see even though the root cause are all from template substitution, the "implicit_convert" and "determine_specialization" are two different path. Should we dup this or create a new, considering the fix might be quite different in these two cases? Do we force developper to fix both cases when submitting a patch?




template<typename ...Ts>
void foo(Ts...);
template<>
void foo<int[]>(int*){}


<source>:3:19: error: no matches converting function 'foo' to type 'void (*)(int*)'
    3 | void (*f)(int*) = foo<int[]>;
      |                   ^~~~~~~~~~
<source>:2:6: note: candidate is: 'template<class ... Ts> void foo(Ts ...)'
    2 | void foo(Ts...);
      |      ^~~
<source>:5:6: error: template-id 'foo<int [3]>' for 'void foo(int*)' does not match any template declaration
    5 | void foo<int[3]>(int*){}
      |      ^~~~~~~~~~~
<source>:2:6: note: candidate is: 'template<class ... Ts> void foo(Ts ...)'
    2 | void foo(Ts...);
      |      ^~~