I have the following class:
template <typename T=void>
class Foo{
public:
Foo(){};
template <typename = typename std::enable_if_t<!std::is_void<T>::value, std::nullptr_t>>
Foo(const T&){};
};
int main() {
Foo<void> v;
}
v is created using the first constructor. Therefore, there is no need to create the second constructor for Foo<void>.
Why does it get created anyways?
The problem is that explicitly creating the second constructor with the type void bypasses SFINAE, and tries to make a parameter of const void&. This is obviously not allowed.
How can I prevent the second constructor from being valid if T is void?