aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/spaceship-synth1.C
blob: 1872fb5382ca364d2ad2a33e238d0275623375cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Test with all operators explicitly defaulted.
// { dg-do run { target c++20 } }

#include <compare>

struct D
{
  int i;
  auto operator<=>(const D& x) const = default;
  bool operator==(const D& x) const = default;
  bool operator!=(const D& x) const = default;
  bool operator<(const D& x) const = default;
  bool operator<=(const D& x) const = default;
  bool operator>(const D& x) const = default;
  bool operator>=(const D& x) const = default;
};

#define assert(X) do { if (!(X)) __builtin_abort(); } while (0)

int main()
{
  D d{42};
  D d2{24};

  assert (is_eq (d <=> d));
  assert (is_lteq (d <=> d));
  assert (is_gteq (d <=> d));
  assert (is_lt (d2 <=> d));
  assert (is_lteq (d2 <=> d));
  assert (is_gt (d <=> d2));
  assert (is_gteq (d <=> d2));

  assert (d == d);
  assert (!(d2 == d));
  assert (!(d == d2));
  assert (d != d2);
  assert (!(d2 != d2));

  assert (d2 < d);
  assert (d2 <= d);
  assert (d > d2);
  assert (d >= d2);
}