| 1 |
// Copyright (C) 2020-2025 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. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++20 } } |
| 19 |
|
| 20 |
#include <array> |
| 21 |
#include <testsuite_hooks.h> |
| 22 |
|
| 23 |
template<typename T> |
| 24 |
constexpr auto |
| 25 |
cmp_array(T t) |
| 26 |
{ |
| 27 |
std::array<T, 2> a{ T{1}, t }; |
| 28 |
std::array<T, 2> b{ T{1}, T{2} }; |
| 29 |
return a <=> b; |
| 30 |
} |
| 31 |
|
| 32 |
void |
| 33 |
test01() |
| 34 |
{ |
| 35 |
static_assert( cmp_array((unsigned char)1) < 0 ); |
| 36 |
static_assert( cmp_array((unsigned char)2) == 0 ); |
| 37 |
static_assert( cmp_array((unsigned char)3) > 0 ); |
| 38 |
|
| 39 |
static_assert( cmp_array((signed char)-1) < 0 ); |
| 40 |
static_assert( cmp_array((signed char)2) == 0 ); |
| 41 |
static_assert( cmp_array((signed char)3) > 0 ); |
| 42 |
|
| 43 |
static_assert( cmp_array(std::byte{1}) < 0 ); |
| 44 |
static_assert( cmp_array(std::byte{2}) == 0 ); |
| 45 |
static_assert( cmp_array(std::byte{3}) > 0 ); |
| 46 |
|
| 47 |
static_assert( cmp_array((unsigned int)1) < 0 ); |
| 48 |
static_assert( cmp_array((unsigned int)2) == 0 ); |
| 49 |
static_assert( cmp_array((unsigned int)333) > 0 ); |
| 50 |
static_assert( cmp_array((unsigned int)4444) > 0 ); |
| 51 |
static_assert( cmp_array((unsigned int)55555) > 0 ); |
| 52 |
static_assert( cmp_array((unsigned int)0x66666666) > 0 ); |
| 53 |
|
| 54 |
static_assert( cmp_array((signed int)-1) < 0 ); |
| 55 |
static_assert( cmp_array((signed int)2) == 0 ); |
| 56 |
static_assert( cmp_array((signed int)333) > 0 ); |
| 57 |
static_assert( cmp_array((signed int)-4444) < 0 ); |
| 58 |
static_assert( cmp_array((signed int)55555) > 0 ); |
| 59 |
static_assert( cmp_array((signed int)-0x66666666) < 0 ); |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
test02() |
| 64 |
{ |
| 65 |
unsigned char uc = 1; |
| 66 |
VERIFY( cmp_array(uc) < 0 ); |
| 67 |
uc = 2; |
| 68 |
VERIFY( cmp_array(uc) == 0 ); |
| 69 |
uc = 3; |
| 70 |
VERIFY( cmp_array(uc) > 0 ); |
| 71 |
|
| 72 |
signed char sc = -1; |
| 73 |
VERIFY( cmp_array(sc) < 0 ); |
| 74 |
sc = 2; |
| 75 |
VERIFY( cmp_array(sc) == 0 ); |
| 76 |
sc = 3; |
| 77 |
VERIFY( cmp_array(sc) > 0 ); |
| 78 |
|
| 79 |
std::byte b{1}; |
| 80 |
VERIFY( cmp_array(b) < 0 ); |
| 81 |
b = std::byte{2}; |
| 82 |
VERIFY( cmp_array(b) == 0 ); |
| 83 |
b = std::byte{3}; |
| 84 |
VERIFY( cmp_array(b) > 0 ); |
| 85 |
|
| 86 |
unsigned int ui = 1; |
| 87 |
VERIFY( cmp_array(ui) < 0 ); |
| 88 |
ui = 2; |
| 89 |
VERIFY( cmp_array(ui) == 0 ); |
| 90 |
ui = 333; |
| 91 |
VERIFY( cmp_array(ui) > 0 ); |
| 92 |
ui = 4444; |
| 93 |
VERIFY( cmp_array(ui) > 0 ); |
| 94 |
ui = 555555; |
| 95 |
VERIFY( cmp_array(ui) > 0 ); |
| 96 |
ui = 0x66666666; |
| 97 |
VERIFY( cmp_array(ui) > 0 ); |
| 98 |
|
| 99 |
signed int si = -1; |
| 100 |
VERIFY( cmp_array(si) < 0 ); |
| 101 |
si = 2; |
| 102 |
VERIFY( cmp_array(si) == 0 ); |
| 103 |
si = 333; |
| 104 |
VERIFY( cmp_array(si) > 0 ); |
| 105 |
si = -4444; |
| 106 |
VERIFY( cmp_array(si) < 0 ); |
| 107 |
si = 555555; |
| 108 |
VERIFY( cmp_array(si) > 0 ); |
| 109 |
si = -0x66666666; |
| 110 |
VERIFY( cmp_array(si) < 0 ); |
| 111 |
} |
| 112 |
|
| 113 |
int |
| 114 |
main() |
| 115 |
{ |
| 116 |
test01(); |
| 117 |
test02(); |
| 118 |
} |