1 // { dg-do compile { target c++20 } }
4 concept Class = __is_class(T);
7 concept Union = __is_union(T);
10 concept One = sizeof(T) >= 4;
13 concept Two = One<T> && sizeof(T) >= 8;
16 template<typename T> requires true struct ok { };
17 template<typename T> requires false struct err { };
20 err<int> err1; // { dg-error "template constraint failure" }
21 err<int>* err2; // { dg-error "template constraint failure" }
28 template<Class T> // { dg-error "template parameter | different constraints" }
37 struct S2; // { dg-error "redeclaration | different constraints" }
40 // Check non-overlapping specializations
42 struct S3 { static const int value = 0; };
46 struct S3<T> { static const int value = 1; };
50 struct S3<T> { static const int value = 2; };
55 static_assert(S3<int>::value == 0, "");
56 static_assert(S3<S>::value == 1, "");
57 static_assert(S3<U>::value == 2, "");
59 // Check ordering of partial specializations
61 struct S4 { static const int value = 0; };
65 struct S4<T> { static const int value = 1; };
69 struct S4<T> { static const int value = 2; };
71 struct one_type { char x[4]; };
72 struct two_type { char x[8]; };
74 static_assert(S4<char>::value == 0, "");
75 static_assert(S4<one_type>::value == 1, "");
76 static_assert(S4<two_type>::value == 2, "");
78 // Specializations are more specialized.
79 template<typename T> requires Two<T> struct S5 { };
80 template<typename T> requires One<T> struct S5<T> { }; // { dg-error "does not specialize" }
82 // Constraints are checked even when decls are not instantiatied.
83 S5<one_type>* x4b; // { dg-error "constraint|invalid" }
87 concept IsInt = __is_same_as(T,int);
101 A a2(1.0); // { dg-error "class template argument deduction | no matching function for call" }
114 struct S6<T>::Inner { }; // { dg-error "does not match" }