Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/spaceship-scalar1a.C

raw
1 // { dg-do run { target c++20 } }
2
3 #include <compare>
4
5 #define assert(X) do { if (!(X)) __builtin_abort(); } while(0)
6
7 template <class T, class U, class R>
8 constexpr bool check(T a, U b, R expected)
9 {
10 auto r = a <=> b;
11 static_assert (__is_same_as (decltype (r), R));
12 return r == expected;
13 }
14
15 int main()
16 {
17 static_assert (check (1, 2, std::strong_ordering::less));
18
19 enum E1 { a = 0 };
20 static_assert (check (a, 1, std::strong_ordering::less));
21
22 enum class E2 { a, b };
23 static_assert (check (E2::a, E2::b, std::strong_ordering::less));
24
25 int ar[2];
26 static_assert (check (&ar[1], &ar[0], std::strong_ordering::greater));
27
28 static_assert (check (3.14, 3.14, std::partial_ordering::equivalent));
29 }