| 1 |
// RUN: %clang_cc1 -std=c++2a -verify %s |
| 2 |
|
| 3 |
namespace std { |
| 4 |
struct strong_ordering { |
| 5 |
int n; |
| 6 |
constexpr operator int() const { return n; } |
| 7 |
static const strong_ordering less, equal, greater; |
| 8 |
}; |
| 9 |
constexpr strong_ordering strong_ordering::less{-1}, strong_ordering::equal{0}, strong_ordering::greater{1}; |
| 10 |
} |
| 11 |
|
| 12 |
struct A { |
| 13 |
int a, b[3], c; |
| 14 |
std::strong_ordering operator<=>(const A&) const = default; |
| 15 |
}; |
| 16 |
|
| 17 |
static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 5}); |
| 18 |
static_assert(A{1, 2, 3, 4, 5} <= A{0, 20, 3, 4, 5}); // expected-error {{failed}} |
| 19 |
static_assert(A{1, 2, 3, 4, 5} <= A{1, 0, 30, 4, 5}); // expected-error {{failed}} |
| 20 |
static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 0, 40, 5}); // expected-error {{failed}} |
| 21 |
static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 0, 50}); // expected-error {{failed}} |
| 22 |
static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 0}); // expected-error {{failed}} |
| 23 |
|
| 24 |
struct reverse_compare { |
| 25 |
int n; |
| 26 |
constexpr explicit reverse_compare(std::strong_ordering o) : n(-o.n) {} |
| 27 |
constexpr operator int() const { return n; } |
| 28 |
}; |
| 29 |
|
| 30 |
struct B { |
| 31 |
int a, b[3], c; |
| 32 |
friend reverse_compare operator<=>(const B&, const B&) = default; |
| 33 |
}; |
| 34 |
static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 5}); |
| 35 |
static_assert(B{1, 2, 3, 4, 5} >= B{0, 20, 3, 4, 5}); // expected-error {{failed}} |
| 36 |
static_assert(B{1, 2, 3, 4, 5} >= B{1, 0, 30, 4, 5}); // expected-error {{failed}} |
| 37 |
static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 0, 40, 5}); // expected-error {{failed}} |
| 38 |
static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 0, 50}); // expected-error {{failed}} |
| 39 |
static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 0}); // expected-error {{failed}} |