Multiple package extensions within a class with a fixed number of template arguments

Is this code well-formed? Declaring the function template itself gives an error in both clang and gcc, although Ts may 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>()); } 

A function call gives this error in gcc, which makes no sense. No conversion to int :

 note: cannot convert 'std::pair<int, int>()' (type 'std::pair<int, int>') to type 'int' 
+5
source share
1 answer

[temp.res] / 8:

If any actual specialization of the variational template requires an empty template package of parameters, the template is poorly formed, no diagnostics are required.

Any valid specialization f requires Ts be an empty package. Therefore, the program is a poorly formed NDR. Both compilers are correct.

Regarding GCC diagnostics, this seems to be due to its habit of using int as a placeholder for “what looks like a type but doesn't make sense” for error recovery purposes.

+4
source

Source: https://habr.com/ru/post/1232846/


All Articles