40 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -verify %s2 3namespace 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 12struct A {13 int a, b[3], c;14 std::strong_ordering operator<=>(const A&) const = default;15};16 17static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 5});18static_assert(A{1, 2, 3, 4, 5} <= A{0, 20, 3, 4, 5}); // expected-error {{failed}}19static_assert(A{1, 2, 3, 4, 5} <= A{1, 0, 30, 4, 5}); // expected-error {{failed}}20static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 0, 40, 5}); // expected-error {{failed}}21static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 0, 50}); // expected-error {{failed}}22static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 0}); // expected-error {{failed}}23 24struct 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 30struct B {31 int a, b[3], c;32 friend reverse_compare operator<=>(const B&, const B&) = default;33};34static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 5});35static_assert(B{1, 2, 3, 4, 5} >= B{0, 20, 3, 4, 5}); // expected-error {{failed}}36static_assert(B{1, 2, 3, 4, 5} >= B{1, 0, 30, 4, 5}); // expected-error {{failed}}37static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 0, 40, 5}); // expected-error {{failed}}38static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 0, 50}); // expected-error {{failed}}39static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 0}); // expected-error {{failed}}40