Playing with C++17 auto
template arguments I've encountered another g++/clang++ disagreement.
Given the following simple code
template <auto>
struct foo;
template <int I>
struct foo<I>
{ };
int main ()
{
foo<42l> f42; // <--- long constant, not int constant
(void)f42; // avoid the "unused variable" warning
}
I see that clang++ (8.0.0, by example) compile the code where g++ (9.2.0, by example) gives the following error
prog.cc: In function 'int main()':
prog.cc:12:13: error: aggregate 'foo<42> f42' has incomplete type and cannot be defined
12 | foo<42l> f42;
| ^~~
Both compilers compile if we use a int
constant instead of a long
constant
foo<42> f42; // compile with both clang++ and g++
So I have two questions for C++ language layers
(1) it's legal, in C++17, specialize a template, declared receiving an auto
template parameter, for a value of a specific type (as the foo
specialization in my code)?
(2) if the answer to the preceding question is "yes", a template specialization can intercept a value of a different (but convertible) type?
Question (2) is almost: is right clang++ or g++?