| 1 | // { dg-do run { target c++20 } } |
| 2 | |
| 3 | #include <utility> |
| 4 | #include <limits> |
| 5 | #include <testsuite_hooks.h> |
| 6 | |
| 7 | void |
| 8 | test01() |
| 9 | { |
| 10 | unsigned int u = std::numeric_limits<unsigned int>::max(); |
| 11 | int s = -1; |
| 12 | VERIFY( !std::cmp_greater(s, u) ); |
| 13 | VERIFY( std::cmp_greater(u, s) ); |
| 14 | u = (unsigned) std::numeric_limits<int>::max() + 1U; |
| 15 | VERIFY( !std::cmp_greater(s, u) ); |
| 16 | VERIFY( std::cmp_greater(u, s) ); |
| 17 | } |
| 18 | |
| 19 | constexpr bool |
| 20 | test02() |
| 21 | { |
| 22 | unsigned int u = std::numeric_limits<unsigned int>::max(); |
| 23 | int s = -1; |
| 24 | if (std::cmp_greater(s, u)) |
| 25 | throw 1; |
| 26 | if (!std::cmp_greater(u, s)) |
| 27 | throw 2; |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | void |
| 32 | test03() |
| 33 | { |
| 34 | short ss = -1; |
| 35 | int s = -1; |
| 36 | VERIFY( !std::cmp_greater(s, ss) ); |
| 37 | VERIFY( !std::cmp_greater(ss, s) ); |
| 38 | |
| 39 | unsigned int u = (unsigned int) -1; |
| 40 | VERIFY( !std::cmp_greater(s, u) ); |
| 41 | VERIFY( std::cmp_greater(u, s) ); |
| 42 | VERIFY( !std::cmp_greater(ss, u) ); |
| 43 | VERIFY( std::cmp_greater(u, ss) ); |
| 44 | |
| 45 | unsigned long long ul = (unsigned long long) -1; |
| 46 | VERIFY( !std::cmp_greater(s, ul) ); |
| 47 | VERIFY( std::cmp_greater(ul, s) ); |
| 48 | VERIFY( !std::cmp_greater(ss, ul) ); |
| 49 | VERIFY( std::cmp_greater(ul, ss) ); |
| 50 | VERIFY( !std::cmp_greater(u, ul) ); |
| 51 | VERIFY( std::cmp_greater(ul, u) ); |
| 52 | } |
| 53 | |
| 54 | int |
| 55 | main() |
| 56 | { |
| 57 | test01(); |
| 58 | static_assert( test02() ); |
| 59 | test03(); |
| 60 | } |