Let's consider a very basic case of a template class for which only specializations are valid:
template<bool B>
struct OnlyTrue; // { static_assert(B != B, "Only true!"; };
template<> struct OnlyTrue<true> { static constexpr bool value = true; };
static constexpr bool b = OnlyTrue<true>::value;
An example above effectively disallows using OnlyTrue<false>
in the program by making it incomplete. An alternative would be uncommenting static_assert
- and making it complete, albeit uncompilable. The benefit of this approach would be that a more human-friendly diagnostic would be generated if instantiated with disallowed value. (See Mapping an integral template parameter value onto a primitive type for a bit more meaningful example of the same technique).
Now to the question - would [temp.res]/8 in latest C++ standard, in particular, 8.1:
The program is ill-formed, no diagnostic required, if: ... no valid specialization can be generated for a template or a substatement of a
constexpr if
statement within a template and the template is not instantiated ...
Make the above snippet ill-formed with no diagnostic required?