Is this code well-formed? The declaration of the function template itself gives an error in both clang and gcc even though Ts
could well be empty.
// error: too many template arguments for class template 'pair'
template<class I, class U, class... Ts>
void f(std::pair<I,U,Ts...>);
int main()
{
f(std::pair<int,int>());
}
The function call gives this error in gcc which doesn't make sense. There is no conversion to int
:
note: cannot convert 'std::pair<int, int>()' (type 'std::pair<int, int>') to type 'int'
[temp.res]/8:
If every valid specialization of a variadic template requires an empty template parameter pack, the template is ill-formed, no diagnostic required.
Every valid specialization of f
would require Ts
to be an empty pack. Therefore the program is ill-formed NDR. Both compilers are correct.
As to GCC's diagnostic, that seems to be due to its habit of using int
as a placeholder for "something that looks like a type but doesn't make sense" for error recovery purposes.
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