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