Reputation: 10480
There's an example on cppreference about the using alias. This example fails because int
has no member foo
:
template<typename...> using void_t = void;
template<typename T> void_t<typename T::foo> f();
f<int>(); // error, int does not have a nested type foo
This is clear, but when I tried putting the void_t
part in the parameter list it unexpectedly compiled:
template<typename...> using void_t = void;
template<typename T> void f(void_t<typename T::foo>);
f<int>();
It compiles on clang but not in gcc. Is this a bug?
Upvotes: 4
Views: 342
Reputation: 275385
template<class...>struct voider{using type=void;};
template<class...Ts>using void_t=typename voider<Ts...>::type;
there is an ambiguity in the C++11 standard about whether non-used template parameters to template using aliases that are invalid types/expressions are a substitution failure or not.
gcc and clang interpreted the clause differently, which is what I think you are seeing. The above void_t
should make it work the same in both gcc and clang.
Upvotes: 8