// { dg-do compile { target c++20 } } template concept Class = __is_class(T); template concept Union = __is_union(T); template concept One = sizeof(T) >= 4; template concept Two = One && sizeof(T) >= 8; // Basic checks template requires true struct ok { }; template requires false struct err { }; ok ok1; err err1; // { dg-error "template constraint failure" } err* err2; // { dg-error "template constraint failure" } // Redeclarations template requires Class struct S1; template // { dg-error "template parameter | different constraints" } struct S1 { }; template requires Class struct S2; template requires Union struct S2; // { dg-error "redeclaration | different constraints" } // Check non-overlapping specializations template struct S3 { static const int value = 0; }; template requires Class struct S3 { static const int value = 1; }; template requires Union struct S3 { static const int value = 2; }; struct S { }; union U { }; static_assert(S3::value == 0, ""); static_assert(S3::value == 1, ""); static_assert(S3::value == 2, ""); // Check ordering of partial specializations template struct S4 { static const int value = 0; }; template requires One struct S4 { static const int value = 1; }; template requires Two struct S4 { static const int value = 2; }; struct one_type { char x[4]; }; struct two_type { char x[8]; }; static_assert(S4::value == 0, ""); static_assert(S4::value == 1, ""); static_assert(S4::value == 2, ""); // Specializations are more specialized. template requires Two struct S5 { }; template requires One struct S5 { }; // { dg-error "does not specialize" } // Constraints are checked even when decls are not instantiatied. S5* x4b; // { dg-error "constraint|invalid" } // Deduction guides template concept IsInt = __is_same_as(T,int); template struct A { int i; A(...); }; template requires IsInt A(I) -> A; A a(1); A a2(1.0); // { dg-error "class template argument deduction | no matching function for call" } template struct S6 { template requires true struct Inner; }; template template struct S6::Inner { }; // { dg-error "does not match" }