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