Reputation: 13876
In a template specialization I have a template argument with an enable_if with parameter that results in the enable_if not having a 'type' member, and so that template specialization should fail, but not create an error:
#include <type_traits>
template <typename value_t_arg, typename T = void>
struct underlyingtype
{
using underlyingtype_t = value_t_arg;
};
template <typename value_t_arg>
struct underlyingtype < value_t_arg, typename std::enable_if<false>::type>
// std::enable_if<false> has no 'type' member, and so substitution should fail,
// but no create an error, right?
{
//using underlyingtype_t = value_t_arg::integral_t;
};
Why is there an error created here?
Upvotes: 2
Views: 124
Reputation: 28416
It's SFINAE, not FINAE. For the compiler to be happy with std::enable_if<false>::type
you'd need the latter, which would mean something nonsensical.
Upvotes: 2
Reputation: 96286
Your code is ill-formed (no diagnostic required) because the condition is always false regardless of the template argument, meaning the specialization would be ill-formed for every possible template argument.
The program is ill-formed, no diagnostic required, if:
— no valid specialization can be generated for a template ... and the template is not instantiated, ...
Partial specializations appear to count as "templates" for the purposes of this section.
Upvotes: 4