https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111662
Bug ID: 111662
Summary: Rejects valid: cv-qualifiers are not removed from
function parameters of variadic templated function
types
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: janschultke at googlemail dot com
Target Milestone: ---
## Code to reproduce
template<class... Ts>
void f(Ts...) {}
void(*pfi)(int) = &f<int>; // OK
void(*pfci)(int) = &f<const int>; // error
void(*pcfi)(const int) = &f<int>; // OK
void(*pcfci)(const int) = &f<const int>; // error
> <source>:5:21: error: no matches converting function 'f' to type 'void
> (*)(int)'
> 5 | void(*pfci)(int) = &f<const int>; // error
> | ^~~~~~~~~~~~
> <source>:2:6: note: candidate is: 'template<class ... Ts> void f(Ts ...)'
> 2 | void f(Ts...) {}
> | ^
## Explanation
The error is nonsensical because the type of &f<const int> is already
void(*)(int). No conversion is required.
According to [dcl.fct] p5, cv-qualifiers are not part of the function type:
> After producing the list of parameter types,
> any top-level cv-qualifiers modifying a parameter type are deleted
> when forming the function type.
Variadic function templates are not exempt from this rule, and GCC should not
reject this code. Making f non-templated, or using a single T parameter instead
of a Ts... parameter pack makes this code compile.