Is static_assert
required to fail when processing an ill-formed-no-diagnostic-required (IFNDR) expression, or can the compiler ignore it and pass successfully the static_assert
, as no diagnostic is required...?
The following code has some IFNDR cases. GCC, Clang and MSVC differ in their results for the static_assert
:
template<typename T> concept A = T::value || true;
template<typename U> concept B = A<U*>;
template<typename V> concept C = A<V&>;
int main(){
static_assert(B<int&>); // clang and msvc rejects gcc accepts, ill-formed (int&*)
static_assert(C<void>); // clang and msvc rejects gcc accepts, ill-formed (void&)
}
The question popped up following this recent interesting question: C++20 Concepts: Constraint Normalization. For explanation and a reference to the spec, regarding concepts-constraint-normalization that create an ill-formed expression follow the above link.
INFDR is, well, IFNDR, immediately when the concept-id is analyzed. This isn’t SFINAE, where some sort of context can “capture” the failure and respond to it.