I expect the following to be ill formed NDR, but it seems not :-(
#include <type_traits>
template <typename T, typename Enabler = void>
struct is_complete : std::false_type {};
template <typename T>
struct is_complete<T, std::void_t<decltype(sizeof(T) != 0)>> : std::true_type {};
class X;
static_assert(!is_complete<X>::type{}); // incomplete type
class X {};
static_assert(!is_complete<X>::type{}); // complete, but already instantiated
Note: Assuming sizeof(T) != 0
is valid for completeness traits (as no types can have sizeof(T) == 0
, using other constant would force to find a better name for the traits :-) )
It is a variation of the code from Is a specialization implicitly instantiated if it has already been implicitly instantiated?, where the program has been declared ill-formed program, No Diagnostic Required (NDR), as the method is_complete_helper<X>::test<X>
has 2 different meanings depending of the points of instantiation.
References which seems near to make the program ill formed, but doesn't as I understand:
the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template.
A specialization for a function template, a member function template, or of a member function or static data member of a class template may have multiple points of instantiations within a translation unit, and in addition to the points of instantiation described above, for any such specialization that has a point of instantiation within the translation unit, the end of the translation unit is also considered a point of instantiation. A specialization for a class template has at most one point of instantiation within a translation unit. A specialization for any template may have points of instantiation in multiple translation units. If two different points of instantiation give a template specialization different meanings according to the one-definition rule, the program is ill-formed, no diagnostic required.
I'm wrong ? or unfortunately this program is correct.