tsn*_*rri 9 c++ templates language-lawyer c++11
Consider the following code (Godbolt):
#include <tuple>
#include <type_traits> // std::false_type, std::true_type
template <typename t_tuple, auto t_size = std::tuple_size_v<t_tuple>>
struct test : std::false_type {};
template <typename t_tuple>
struct test<t_tuple, 0> : std::true_type {};
int main(int argc, char **argv)
{
static_assert(test<std::tuple<>>::value);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Clang and some other compilers accept the code but in GCC and ICC the static assertion fails. Either changing the type of t_size from auto to std::size_t or casting the zero in the specialisation to std::size_t alleviates the issue. What I would like to know is:
int instead of std::size_t when setting the type of the second template parameter to auto? Obviously (?) the types do not match (since the type of std::tuple_size_v is std::size_t) but I was expecting the compiler to at least warn me about something.auto with non-type template parameters?(I checked this question but it had to do with const/volatile.)