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