| 1 |
// PR c++/118387 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
#include <compare> |
| 5 |
|
| 6 |
struct A { |
| 7 |
int operator<=> (const A &) const; |
| 8 |
}; |
| 9 |
|
| 10 |
struct B { |
| 11 |
A a; |
| 12 |
int operator<=> (const B &) const = default; // { dg-message "'constexpr int B::operator<=>\\\(const B&\\\) const' is implicitly deleted because the default definition would be ill-formed:" } |
| 13 |
}; // { dg-error "invalid 'static_cast' from type 'const std::strong_ordering' to type 'int'" "" { target *-*-* } .-1 } |
| 14 |
|
| 15 |
struct C { |
| 16 |
int operator<=> (const C &) const = default; // { dg-message "'constexpr int C::operator<=>\\\(const C&\\\) const' is implicitly deleted because the default definition would be ill-formed:" } |
| 17 |
}; // { dg-error "invalid 'static_cast' from type 'const std::strong_ordering' to type 'int'" "" { target *-*-* } .-1 } |
| 18 |
|
| 19 |
struct D { |
| 20 |
auto operator<=> (const D &) const = default; |
| 21 |
}; |
| 22 |
|
| 23 |
struct E { |
| 24 |
D a; // { dg-error "three-way comparison of 'E::a' has type 'std::strong_ordering', which does not convert to 'int'" } |
| 25 |
int operator<=> (const E &) const = default; // { dg-message "'constexpr int E::operator<=>\\\(const E&\\\) const' is implicitly deleted because the default definition would be ill-formed:" } |
| 26 |
}; // { dg-error "invalid 'static_cast' from type 'const std::strong_ordering' to type 'int'" "" { target *-*-* } .-1 } |
| 27 |
|
| 28 |
struct F { |
| 29 |
A a; |
| 30 |
int operator<=> (const F &) const = default; |
| 31 |
}; |
| 32 |
|
| 33 |
struct G { |
| 34 |
int operator<=> (const G &) const = default; |
| 35 |
}; |
| 36 |
|
| 37 |
struct H { |
| 38 |
D a; |
| 39 |
int operator<=> (const H &) const = default; |
| 40 |
}; |
| 41 |
|
| 42 |
auto |
| 43 |
foo (B a, B b) |
| 44 |
{ |
| 45 |
return a <=> b; // { dg-error "use of deleted function 'constexpr int B::operator<=>\\\(const B&\\\) const'" } |
| 46 |
} |
| 47 |
|
| 48 |
auto |
| 49 |
bar (C a, C b) |
| 50 |
{ |
| 51 |
return a <=> b; // { dg-error "use of deleted function 'constexpr int C::operator<=>\\\(const C&\\\) const'" } |
| 52 |
} |
| 53 |
|
| 54 |
auto |
| 55 |
baz (E a, E b) |
| 56 |
{ |
| 57 |
return a <=> b; // { dg-error "use of deleted function 'constexpr int E::operator<=>\\\(const E&\\\) const'" } |
| 58 |
} |