testsuite: Fix up pr111150* tests on i686-linux [PR111150]
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / comparisons / algorithms / weak_order.cc
blob1f2e139b605376fc9c3bf73cd475516d92f2e90c
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++20 } }
20 #include <compare>
21 #include <limits>
22 #include <testsuite_hooks.h>
24 using std::weak_order;
25 using std::weak_ordering;
27 void
28 test01()
30 const int one = 1, two = 2;
32 static_assert( weak_order(one, two) == weak_ordering::less );
33 static_assert( weak_order(one, one) == weak_ordering::equivalent );
34 static_assert( weak_order(two, one) == weak_ordering::greater );
35 static_assert( noexcept(weak_order(1, 1)) );
38 constexpr weak_ordering different_cv_quals(int i, const int j)
40 return weak_order(i, j);
43 void
44 test02()
46 const int fortytwo = 42, nines = 999, lots = 1000;
48 static_assert( different_cv_quals(fortytwo, nines) == weak_ordering::less );
49 static_assert( different_cv_quals(-nines, -nines) == weak_ordering::equivalent );
50 static_assert( different_cv_quals(-nines, -lots) == weak_ordering::greater );
53 void
54 test03()
56 constexpr double zero = 0.0;
57 static_assert( weak_order(zero, zero) == weak_ordering::equivalent );
58 static_assert( weak_order(-zero, -zero) == weak_ordering::equivalent );
59 static_assert( weak_order(-zero, zero) == weak_ordering::equivalent );
60 static_assert( weak_order(zero, -zero) == weak_ordering::equivalent );
62 constexpr double min = std::numeric_limits<double>::lowest();
63 constexpr double max = std::numeric_limits<double>::max();
64 constexpr double nan = std::numeric_limits<double>::quiet_NaN();
65 constexpr double inf = std::numeric_limits<double>::infinity();
66 constexpr double denorm = std::numeric_limits<double>::denorm_min();
67 constexpr double smallest = std::numeric_limits<double>::min();
68 constexpr double epsilon = std::numeric_limits<double>::epsilon();
69 static_assert( weak_order(denorm, smallest) == weak_ordering::less );
70 static_assert( weak_order(denorm, 0.0) == weak_ordering::greater );
71 // FIXME: these should all use static_assert
72 VERIFY( weak_order(0.0, nan) == weak_ordering::less );
73 static_assert( weak_order(nan, nan) == weak_ordering::equivalent );
74 static_assert( weak_order(nan, -nan) == weak_ordering::greater );
75 static_assert( weak_order(-nan, nan) == weak_ordering::less );
76 VERIFY( weak_order(nan, 0.0) == weak_ordering::greater );
77 VERIFY( weak_order(-nan, 0.0) == weak_ordering::less );
78 VERIFY( weak_order(-nan, min) == weak_ordering::less );
79 static_assert( weak_order(-inf, min) == weak_ordering::less );
80 VERIFY( weak_order(-nan, -inf) == weak_ordering::less );
81 VERIFY( weak_order(-inf, -nan) == weak_ordering::greater );
82 static_assert( weak_order(max, inf) == weak_ordering::less );
83 static_assert( weak_order(inf, max) == weak_ordering::greater );
84 VERIFY( weak_order(inf, nan) == weak_ordering::less );
85 static_assert( weak_order(1.0, 1.0+epsilon) == weak_ordering::less );
88 namespace N
90 struct X { int i; };
92 constexpr weak_ordering operator<=>(X l, X r)
94 if (l.i < 0 && r.i < 0)
95 return weak_ordering::equivalent;
96 return r.i <=> l.i;
99 constexpr bool operator==(X l, X r) { return std::is_eq(l <=> r); }
101 static_assert(std::three_way_comparable<X>);
104 void
105 test04()
107 using N::X;
108 X one{1};
109 X negone{-1};
111 // FIXME: these should all use static_assert
112 VERIFY( weak_order(one, X{1}) == weak_ordering::equivalent );
113 VERIFY( weak_order(negone, X{-2}) == weak_ordering::equivalent );
114 VERIFY( weak_order(one, X{2}) == weak_ordering::greater );
115 static_assert( !noexcept(weak_order(X{1}, X{2})) );
118 int main()
120 test01();
121 test02();
122 test03();
123 test04();