| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-options "-fconcepts" } |
| 3 |
// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } |
| 4 |
|
| 5 |
struct dog {}; |
| 6 |
struct cat {}; |
| 7 |
|
| 8 |
void pet(dog); |
| 9 |
void pet(cat); |
| 10 |
|
| 11 |
template <class T> |
| 12 |
concept has_member_pet = requires(T t) { t.pet(); }; |
| 13 |
|
| 14 |
template <class T> |
| 15 |
concept has_default_pet = T::is_pettable; |
| 16 |
|
| 17 |
template <class T> |
| 18 |
concept pettable = has_member_pet<T> or has_default_pet<T>; |
| 19 |
|
| 20 |
void pet(pettable auto t); |
| 21 |
|
| 22 |
struct lizard {}; |
| 23 |
|
| 24 |
int main() { |
| 25 |
pet(lizard{}); // { dg-error "no matching function for call to 'pet\\\(lizard\\\)'" } |
| 26 |
} |
| 27 |
|
| 28 |
/* { dg-begin-multiline-output "" } |
| 29 |
* there are 3 candidates |
| 30 |
* candidate 1: 'template<class auto:1> requires pettable<auto:1> void pet(auto:1)' |
| 31 |
* template argument deduction/substitution failed: |
| 32 |
* constraints not satisfied |
| 33 |
* In substitution of 'template<class auto:1> requires pettable<auto:1> void pet(auto:1) [with auto:1 = lizard]': |
| 34 |
* required from here |
| 35 |
* required for the satisfaction of 'pettable<auto:1>' [with auto:1 = lizard] |
| 36 |
* no operand of the disjunction is satisfied |
| 37 |
* set '-fconcepts-diagnostics-depth=' to at least 2 for more detail |
| 38 |
* candidate 2: 'void pet(dog)' |
| 39 |
* no known conversion for argument 1 from 'lizard' to 'dog' |
| 40 |
* candidate 3: 'void pet(cat)' |
| 41 |
* no known conversion for argument 1 from 'lizard' to 'cat' |
| 42 |
{ dg-end-multiline-output "" } */ |