1 // { dg-do compile { target c++2a } } 2 // { dg-additional-options "-fconcepts-ts -fconcepts-diagnostics-depth=2" } 3 4 // Test conversion requirements (not in C++20) 5 6 // req9.C 7 8 template<typename T> 9 struct S1 { }; 10 11 template<typename T> requires(T x)12concept C = requires(T x) { { x.fn() } -> S1<T>; }; 13 14 template<typename U> 15 requires C<U> fn(U x)16void fn(U x) 17 { 18 x.fn(); 19 } 20 21 struct S2 22 { fnS223 auto fn() const { return S1<S2>(); } 24 }; 25 driver_1()26int driver_1() 27 { 28 fn(S2{}); 29 return 0; 30 } 31 32 // req10.C 33 // Test implicit conversion requirements 34 35 template<typename T, typename U> requires(T & t)36concept ConvertibleTo = requires(T& t) { {t} -> U&; }; // { dg-error "inaccessible" } 37 38 struct B { }; 39 class D : /*private*/ B { }; 40 driver_2()41void driver_2() 42 { 43 static_assert(ConvertibleTo<D, B>()); // { dg-error "cannot call" } 44 static_assert(ConvertibleTo<D, B>); // { dg-error "static assertion failed" } 45 } 46