37 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify2 3// Examples from standard4 5template<typename T, typename U>6concept convertible_to = requires(T t) { U(t); };7 8template<typename T>9concept R = requires (T i) {10 typename T::type;11 {*i} -> convertible_to<const typename T::type&>;12};13 14template<typename T> requires R<T> struct S {};15 16struct T {17 using type = int;18 type i;19 const type &operator*() { return i; }20};21 22using si = S<T>;23 24template<typename T>25requires requires (T x) { x + x; } // expected-note{{because 'x + x' would be invalid: invalid operands to binary expression ('T' and 'T')}}26T add(T a, T b) { return a + b; } // expected-note{{candidate template ignored: constraints not satisfied [with T = T]}}27 28int x = add(1, 2);29int y = add(T{}, T{}); // expected-error{{no matching function for call to 'add'}}30 31template<typename T>32concept C = requires (T x) { x + x; }; // expected-note{{because 'x + x' would be invalid: invalid operands to binary expression ('T' and 'T')}}33template<typename T> requires C<T> // expected-note{{because 'T' does not satisfy 'C'}}34T add2(T a, T b) { return a + b; } // expected-note{{candidate template ignored: constraints not satisfied [with T = T]}}35 36int z = add2(1, 2);37int w = add2(T{}, T{}); // expected-error{{no matching function for call to 'add2'}}