#include <type_traits>
template<typename T>
struct IsComplete final
: std::bool_constant<requires{sizeof(T);}>
{};
int main()
{
struct A;
static_assert(!IsComplete<A>::value); // ok
struct A{};
static_assert(IsComplete<A>::value); // error
}
I expected that the second static_assert should be true as A is a complete type now.
Why does C++20's requires expression not behave as expected?
It's a wrong expectation. To start with, a class template has only one point of instantiation in a translation unit:
Templates never allowed for two points in the program to have a different interpretation of the template for the same set of arguments (an ODR nightmare in the general case). You basically start venturing into nasal-demon territory with your attempt at the trait.
And should you think using C++20 concepts is gonna change anything, you'll dive right into ill-formed; no diagnostic required territory if you conceptify the example
It's not anything new, concepts just add more of the same. A template's meaning for a specific set of arguments must not change if some property of the arguments is different in two different points in the program.
So while a concept (even in pre-C++20 SFINAE hackery) that checks if a type is complete may be written, to use it carelessly is to play with fire.