summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C')
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C113
1 files changed, 113 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C
new file mode 100644
index 00000000000..32314579dcb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth1a.C
@@ -0,0 +1,113 @@
+// Test with all operators explicitly defaulted.
+// { dg-do run { target c++2a } }
+
+#include <compare>
+
+template <class T>
+struct D
+{
+ T 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;
+};
+
+template <class T>
+struct E
+{
+ T i;
+ auto operator<=>(const E& x) const = default;
+ // auto operator==(const E& x) const = default;
+ // auto operator!=(const E& x) const = default;
+ // auto operator<(const E& x) const = default;
+ // auto operator<=(const E& x) const = default;
+ // auto operator>(const E& x) const = default;
+ // auto operator>=(const E& x) const = default;
+};
+
+template <class T>
+struct F
+{
+ T i;
+ constexpr auto operator<=>(T x) const { return i<=>x; }
+ constexpr bool operator== (T x) const { return i==x; }
+};
+
+#define assert(X) do { if (!(X)) __builtin_abort(); } while (0)
+
+template <class T, class U>
+constexpr bool check_eq (T d, U d2)
+{
+ return is_eq (d <=> d2)
+ && is_eq (d2 <=> d)
+ && is_lteq (d <=> d2)
+ && is_lteq (d2 <=> d)
+ && !is_lt (d <=> d2)
+ && !is_lt (d2 <=> d)
+ && is_gteq (d <=> d2)
+ && is_gteq (d2 <=> d)
+ && !is_gt (d <=> d2)
+ && !is_gt (d2 <=> d)
+ && d == d2
+ && d2 == d
+ && !(d != d2)
+ && !(d2 != d)
+ && d >= d2
+ && d <= d2
+ && d2 >= d
+ && d2 <= d
+ && !(d < d2)
+ && !(d2 < d)
+ && !(d > d2)
+ && !(d2 > d);
+}
+
+template <class T, class U>
+constexpr bool check_less (T d, U d2)
+{
+ return !is_eq (d <=> d2)
+ && !is_eq (d2 <=> d)
+ && is_lteq (d <=> d2)
+ && !is_lteq (d2 <=> d)
+ && is_lt (d <=> d2)
+ && !is_lt (d2 <=> d)
+ && !is_gteq (d <=> d2)
+ && is_gteq (d2 <=> d)
+ && !is_gt (d <=> d2)
+ && is_gt (d2 <=> d)
+ && !(d == d2)
+ && !(d2 == d)
+ && (d != d2)
+ && (d2 != d)
+ && !(d >= d2)
+ && (d <= d2)
+ && (d2 >= d)
+ && !(d2 <= d)
+ && (d < d2)
+ && !(d2 < d)
+ && !(d > d2)
+ && (d2 > d);
+}
+
+int main()
+{
+ constexpr D<int> d{42};
+ constexpr D<int> d2{24};
+
+ static_assert (check_eq (d, d));
+ static_assert (check_less (d2, d));
+
+ constexpr E<float> e { 3.14 };
+ constexpr E<float> ee { 2.72 };
+ static_assert (check_eq (e, e));
+ static_assert (check_less (ee, e));
+
+ constexpr F<char> f { 'b' };
+ static_assert (check_eq (f, 'b'));
+ static_assert (check_less (f, 'c'));
+ static_assert (check_less ('a', f));
+}