Is the deduction for f1
and f2
ill-formed?
template<class... T, class U>
void f1(T..., U){}
template<class... T>
void f2(T..., int){}
int main()
{
f1(1);
f2(1);
return 0;
}
g++ accepts both, clang only accepts f2
, and msvc rejects both.
Related standard wording:
[temp.deduct.call]
When a function parameter pack appears in a non-deduced context ([temp.deduct.type]), the type of that parameter pack is never deduced.
[temp.deduct.type]p5
The non-deduced contexts are:
- A function parameter pack that does not occur at the end of the parameter-declaration-list.
So it seems that MSVC is correct in rejecting both?
Does it mean that any instantiation of the templates will be ill-formed, even if you specify the template args explicitly?
f1<int>(1, 2); // ill-formed?
f2<int>(1, 2); // ill-formed?
If that's the case, why allow such declarations at first place?
There's a DR for this specific issue DR1388. Aparently, it seems that GCC and CLANG haven't implemented it yet CLANG DR1388.
Does it mean that any instantiation of the templates will be ill-formed, even if you specify the template args explicitly?
f1<int>(1, 2); // ill-formed? f2<int>(1, 2); // ill-formed?
If that's the case, why allow such declarations at first place?
No if you specify explicitly the template arguments, no deduction occurs and as such the code showed above is legal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With