summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C')
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C48
1 files changed, 48 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C
new file mode 100644
index 00000000000..0fc5aa2c9b8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth3.C
@@ -0,0 +1,48 @@
+// Test for reversed candidates.
+// { dg-do run { target c++2a } }
+
+#include <compare>
+
+struct D
+{
+ int i;
+ auto operator<=>(int x) const { return i<=>x; }
+ bool operator== (int x) const { return i==x; }
+};
+
+#define assert(X) do { if (!(X)) __builtin_abort(); } while (0)
+
+int main()
+{
+ D d{42};
+ int d1 = 42;
+ int d2 = 24;
+
+ assert (is_eq (d <=> d1));
+ assert (is_eq (d1 <=> d));
+ assert (is_lteq (d <=> d1));
+ assert (is_lteq (d1 <=> d));
+ assert (is_gteq (d <=> d1));
+ assert (is_gteq (d1 <=> d));
+ assert (is_lt (d2 <=> d));
+ assert (is_lteq (d2 <=> d));
+ assert (is_gt (d <=> d2));
+ assert (is_gteq (d <=> d2));
+
+ assert (d == d1);
+ assert (d1 == d);
+ assert (!(d2 == d));
+ assert (!(d == d2));
+ assert (d != d2);
+ assert (d2 != d);
+ assert (!(d != d1));
+ assert (!(d1 != d));
+
+ assert (d2 < d);
+ assert (d2 <= d);
+ assert (d1 <= d);
+ assert (d > d2);
+ assert (d >= d2);
+ assert (d >= d1);
+ assert (d <= d1);
+}