This looks like an issue in clang (I've already opened a bug here), but I'd like to be sure that I'm not doing a mistake.
Consider the following code:
#include <type_traits>
#include <cstddef>
template<std::size_t N, std::size_t M, std::enable_if_t<not (N>M)>* = nullptr> // (1)
struct S: public S<N+1, M> { };
template<std::size_t N>
struct S<N, N> { };
int main() {
S<0, 1> c{};
}
It fails to compile with the following error:
8 : error: non-type template argument specializes a template parameter with dependent type 'std::enable_if_t M)> *' (aka 'typename enable_if M), void>::type *')
struct S { };
The same code works as expected using the following line instead of (1):
template<std::size_t N, std::size_t M, typename = std::enable_if_t<not (N>M)>>
The SFINAE expression is almost the same. It is based on a specialization of std::enable_if_t
and I would expect the same result (success or failure) for both of the examples.
Are my expectations wrong?
Note that GCC works fine in either cases.
main
method will be ill-formed. – Johannes Schaub - litbstruct S<N,M,<unnamed>>
. And in your case, the unnamed argument got an invalid type, which will result in ill-formed code. – Johannes Schaub - litbtypename = std::enable_if<...
, this time both with GCC and clang. As an example,S<0, 2>
is accepted, whileS<2, 0>
is not. Theenable_if
won't fail in the first case, but it will in the second. I don't get your point, I'm sorry. – skypjackenable_if
expressions in partial specializations, where they are in SFINAE contexts, but as a type in a primary template they are not SFINAE contexts. And placing it as a default argument probably does something else than what you think it does: You possibly expected this to compile: coliru.stacked-crooked.com/a/486ba2517bf67c18 – Johannes Schaub - litbS<N,M>
, your code is always ill-formed. There is no "not an error" part of SFINAE in there. The term SFINAE is used for cases where substitution fails, but where it is not an error and an alternative declaration can be considered (S<2, 1>
in my example). – Johannes Schaub - litb