xref: /llvm-project/clang/test/CXX/class/class.compare/class.spaceship/p3.cpp (revision e6e6e34b95cfe03275943fde0db259cc7d57f4ad)
1cafc7416SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s
2cafc7416SRichard Smith 
3cafc7416SRichard Smith namespace std {
4cafc7416SRichard Smith   struct strong_ordering {
5cafc7416SRichard Smith     int n;
operator intstd::strong_ordering6cafc7416SRichard Smith     constexpr operator int() const { return n; }
7cafc7416SRichard Smith     static const strong_ordering less, equal, greater;
8cafc7416SRichard Smith   };
9cafc7416SRichard Smith   constexpr strong_ordering strong_ordering::less{-1}, strong_ordering::equal{0}, strong_ordering::greater{1};
10cafc7416SRichard Smith }
11cafc7416SRichard Smith 
12cafc7416SRichard Smith struct A {
13*e6e6e34bSRichard Smith   int a, b[3], c;
14cafc7416SRichard Smith   std::strong_ordering operator<=>(const A&) const = default;
15cafc7416SRichard Smith };
16cafc7416SRichard Smith 
17*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 5});
18*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{0, 20, 3, 4, 5}); // expected-error {{failed}}
19*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{1, 0, 30, 4, 5}); // expected-error {{failed}}
20*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 0, 40, 5}); // expected-error {{failed}}
21*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 0, 50}); // expected-error {{failed}}
22*e6e6e34bSRichard Smith static_assert(A{1, 2, 3, 4, 5} <= A{1, 2, 3, 4, 0}); // expected-error {{failed}}
23cafc7416SRichard Smith 
24cafc7416SRichard Smith struct reverse_compare {
25cafc7416SRichard Smith   int n;
reverse_comparereverse_compare26cafc7416SRichard Smith   constexpr explicit reverse_compare(std::strong_ordering o) : n(-o.n) {}
operator intreverse_compare27cafc7416SRichard Smith   constexpr operator int() const { return n; }
28cafc7416SRichard Smith };
29cafc7416SRichard Smith 
30cafc7416SRichard Smith struct B {
31*e6e6e34bSRichard Smith   int a, b[3], c;
32cafc7416SRichard Smith   friend reverse_compare operator<=>(const B&, const B&) = default;
33cafc7416SRichard Smith };
34*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 5});
35*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{0, 20, 3, 4, 5}); // expected-error {{failed}}
36*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{1, 0, 30, 4, 5}); // expected-error {{failed}}
37*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 0, 40, 5}); // expected-error {{failed}}
38*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 0, 50}); // expected-error {{failed}}
39*e6e6e34bSRichard Smith static_assert(B{1, 2, 3, 4, 5} >= B{1, 2, 3, 4, 0}); // expected-error {{failed}}
40