1 // RUN: %clang_cc1 -std=c++2a -x c++ %s -verify 2 3 static_assert(requires { requires true; }); 4 5 template<typename T> requires requires { requires false; } // expected-note{{because 'false' evaluated to false}} 6 struct r1 {}; 7 8 using r1i = r1<int>; // expected-error{{constraints not satisfied for class template 'r1' [with T = int]}} 9 10 template<typename T> requires requires { requires sizeof(T) == 0; } // expected-note{{because 'sizeof(int) == 0' (4 == 0) evaluated to false}} 11 struct r2 {}; 12 13 using r2i = r2<int>; // expected-error{{constraints not satisfied for class template 'r2' [with T = int]}} 14 15 template<typename T> requires requires (T t) { requires sizeof(t) == 0; } // expected-note{{because 'sizeof (t) == 0' (4 == 0) evaluated to false}} 16 struct r3 {}; 17 18 using r3i = r3<int>; // expected-error{{constraints not satisfied for class template 'r3' [with T = int]}} 19 20 template<typename T> 21 struct X { 22 template<typename U> requires requires (U u) { requires sizeof(u) == sizeof(T); } // expected-note{{because 'sizeof (u) == sizeof(T)' would be invalid: invalid application of 'sizeof' to an incomplete type 'void'}} 23 struct r4 {}; 24 }; 25 26 using r4i = X<void>::r4<int>; // expected-error{{constraints not satisfied for class template 'r4' [with U = int]}} 27 28 // C++ [expr.prim.req.nested] Examples 29 namespace std_example { 30 template<typename U> concept C1 = sizeof(U) == 1; // expected-note{{because 'sizeof(int) == 1' (4 == 1) evaluated to false}} 31 template<typename T> concept D = 32 requires (T t) { 33 requires C1<decltype (+t)>; // expected-note{{because 'decltype(+t)' (aka 'int') does not satisfy 'C1'}} 34 }; 35 operator +std_example::T136 struct T1 { char operator+() { return 'a'; } }; 37 static_assert(D<T1>); 38 template<D T> struct D_check {}; // expected-note{{because 'short' does not satisfy 'D'}} 39 using dc1 = D_check<short>; // expected-error{{constraints not satisfied for class template 'D_check' [with T = short]}} 40 41 template<typename T> 42 concept C2 = requires (T a) { 43 requires sizeof(a) == 4; // OK 44 requires a == 0; // expected-note{{because 'a == 0' would be invalid: constraint variable 'a' cannot be used in an evaluated context}} 45 }; 46 static_assert(C2<int>); // expected-note{{because 'int' does not satisfy 'C2'}} expected-error{{static_assert failed}} 47 }