| 1 |
// Test with all operators explicitly defaulted. |
| 2 |
// { dg-do run { target c++20 } } |
| 3 |
|
| 4 |
#include <compare> |
| 5 |
|
| 6 |
struct D |
| 7 |
{ |
| 8 |
int i; |
| 9 |
auto operator<=>(const D& x) const = default; |
| 10 |
bool operator==(const D& x) const = default; |
| 11 |
bool operator!=(const D& x) const = default; |
| 12 |
bool operator<(const D& x) const = default; |
| 13 |
bool operator<=(const D& x) const = default; |
| 14 |
bool operator>(const D& x) const = default; |
| 15 |
bool operator>=(const D& x) const = default; |
| 16 |
}; |
| 17 |
|
| 18 |
#define assert(X) do { if (!(X)) __builtin_abort(); } while (0) |
| 19 |
|
| 20 |
int main() |
| 21 |
{ |
| 22 |
D d{42}; |
| 23 |
D d2{24}; |
| 24 |
|
| 25 |
assert (is_eq (d <=> d)); |
| 26 |
assert (is_lteq (d <=> d)); |
| 27 |
assert (is_gteq (d <=> d)); |
| 28 |
assert (is_lt (d2 <=> d)); |
| 29 |
assert (is_lteq (d2 <=> d)); |
| 30 |
assert (is_gt (d <=> d2)); |
| 31 |
assert (is_gteq (d <=> d2)); |
| 32 |
|
| 33 |
assert (d == d); |
| 34 |
assert (!(d2 == d)); |
| 35 |
assert (!(d == d2)); |
| 36 |
assert (d != d2); |
| 37 |
assert (!(d2 != d2)); |
| 38 |
|
| 39 |
assert (d2 < d); |
| 40 |
assert (d2 <= d); |
| 41 |
assert (d > d2); |
| 42 |
assert (d >= d2); |
| 43 |
} |