1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
14 // Make sure we can use the following types without including anything else
16 (void)sizeof(int16_t);
17 (void)sizeof(int32_t);
18 (void)sizeof(int64_t);
20 (void)sizeof(uint8_t);
21 (void)sizeof(uint16_t);
22 (void)sizeof(uint32_t);
23 (void)sizeof(uint64_t);
25 (void)sizeof(int_least8_t);
26 (void)sizeof(int_least16_t);
27 (void)sizeof(int_least32_t);
28 (void)sizeof(int_least64_t);
30 (void)sizeof(uint_least8_t);
31 (void)sizeof(uint_least16_t);
32 (void)sizeof(uint_least32_t);
33 (void)sizeof(uint_least64_t);
35 (void)sizeof(int_fast8_t);
36 (void)sizeof(int_fast16_t);
37 (void)sizeof(int_fast32_t);
38 (void)sizeof(int_fast64_t);
40 (void)sizeof(uint_fast8_t);
41 (void)sizeof(uint_fast16_t);
42 (void)sizeof(uint_fast32_t);
43 (void)sizeof(uint_fast64_t);
45 (void)sizeof(intptr_t);
46 (void)sizeof(uintptr_t);
47 (void)sizeof(intmax_t);
48 (void)sizeof(uintmax_t);
54 #include <type_traits>
58 #include "test_macros.h"
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
64 int main(int, char**) {
66 static_assert(sizeof(int8_t)*CHAR_BIT
== 8, "");
67 static_assert(std::is_signed
<int8_t>::value
, "");
69 static_assert(sizeof(int16_t)*CHAR_BIT
== 16, "");
70 static_assert(std::is_signed
<int16_t>::value
, "");
72 static_assert(sizeof(int32_t)*CHAR_BIT
== 32, "");
73 static_assert(std::is_signed
<int32_t>::value
, "");
75 static_assert(sizeof(int64_t)*CHAR_BIT
== 64, "");
76 static_assert(std::is_signed
<int64_t>::value
, "");
79 static_assert(sizeof(uint8_t)*CHAR_BIT
== 8, "");
80 static_assert(std::is_unsigned
<uint8_t>::value
, "");
82 static_assert(sizeof(uint16_t)*CHAR_BIT
== 16, "");
83 static_assert(std::is_unsigned
<uint16_t>::value
, "");
85 static_assert(sizeof(uint32_t)*CHAR_BIT
== 32, "");
86 static_assert(std::is_unsigned
<uint32_t>::value
, "");
88 static_assert(sizeof(uint64_t)*CHAR_BIT
== 64, "");
89 static_assert(std::is_unsigned
<uint64_t>::value
, "");
91 // typedef int_least8_t
92 static_assert(sizeof(int_least8_t)*CHAR_BIT
>= 8, "");
93 static_assert(std::is_signed
<int_least8_t>::value
, "");
94 // typedef int_least16_t
95 static_assert(sizeof(int_least16_t)*CHAR_BIT
>= 16, "");
96 static_assert(std::is_signed
<int_least16_t>::value
, "");
97 // typedef int_least32_t
98 static_assert(sizeof(int_least32_t)*CHAR_BIT
>= 32, "");
99 static_assert(std::is_signed
<int_least32_t>::value
, "");
100 // typedef int_least64_t
101 static_assert(sizeof(int_least64_t)*CHAR_BIT
>= 64, "");
102 static_assert(std::is_signed
<int_least64_t>::value
, "");
104 // typedef uint_least8_t
105 static_assert(sizeof(uint_least8_t)*CHAR_BIT
>= 8, "");
106 static_assert(std::is_unsigned
<uint_least8_t>::value
, "");
107 // typedef uint_least16_t
108 static_assert(sizeof(uint_least16_t)*CHAR_BIT
>= 16, "");
109 static_assert(std::is_unsigned
<uint_least16_t>::value
, "");
110 // typedef uint_least32_t
111 static_assert(sizeof(uint_least32_t)*CHAR_BIT
>= 32, "");
112 static_assert(std::is_unsigned
<uint_least32_t>::value
, "");
113 // typedef uint_least64_t
114 static_assert(sizeof(uint_least64_t)*CHAR_BIT
>= 64, "");
115 static_assert(std::is_unsigned
<uint_least64_t>::value
, "");
117 // typedef int_fast8_t
118 static_assert(sizeof(int_fast8_t)*CHAR_BIT
>= 8, "");
119 static_assert(std::is_signed
<int_fast8_t>::value
, "");
120 // typedef int_fast16_t
121 static_assert(sizeof(int_fast16_t)*CHAR_BIT
>= 16, "");
122 static_assert(std::is_signed
<int_fast16_t>::value
, "");
123 // typedef int_fast32_t
124 static_assert(sizeof(int_fast32_t)*CHAR_BIT
>= 32, "");
125 static_assert(std::is_signed
<int_fast32_t>::value
, "");
126 // typedef int_fast64_t
127 static_assert(sizeof(int_fast64_t)*CHAR_BIT
>= 64, "");
128 static_assert(std::is_signed
<int_fast64_t>::value
, "");
130 // typedef uint_fast8_t
131 static_assert(sizeof(uint_fast8_t)*CHAR_BIT
>= 8, "");
132 static_assert(std::is_unsigned
<uint_fast8_t>::value
, "");
133 // typedef uint_fast16_t
134 static_assert(sizeof(uint_fast16_t)*CHAR_BIT
>= 16, "");
135 static_assert(std::is_unsigned
<uint_fast16_t>::value
, "");
136 // typedef uint_fast32_t
137 static_assert(sizeof(uint_fast32_t)*CHAR_BIT
>= 32, "");
138 static_assert(std::is_unsigned
<uint_fast32_t>::value
, "");
139 // typedef uint_fast64_t
140 static_assert(sizeof(uint_fast64_t)*CHAR_BIT
>= 64, "");
141 static_assert(std::is_unsigned
<uint_fast64_t>::value
, "");
144 static_assert(sizeof(intptr_t) >= sizeof(void*), "");
145 static_assert(std::is_signed
<intptr_t>::value
, "");
147 static_assert(sizeof(uintptr_t) >= sizeof(void*), "");
148 static_assert(std::is_unsigned
<uintptr_t>::value
, "");
151 static_assert(sizeof(intmax_t) >= sizeof(long long), "");
152 static_assert(std::is_signed
<intmax_t>::value
, "");
154 static_assert(sizeof(uintmax_t) >= sizeof(unsigned long long), "");
155 static_assert(std::is_unsigned
<uintmax_t>::value
, "");
158 static_assert(INT8_MIN
== -128, "");
159 static_assert(INT16_MIN
== -32768, "");
160 static_assert(INT32_MIN
== -2147483647 - 1, "");
161 static_assert(INT64_MIN
== -9223372036854775807LL - 1, "");
164 static_assert(INT8_MAX
== 127, "");
165 static_assert(INT16_MAX
== 32767, "");
166 static_assert(INT32_MAX
== 2147483647, "");
167 static_assert(INT64_MAX
== 9223372036854775807LL, "");
170 static_assert(UINT8_MAX
== 255, "");
171 static_assert(UINT16_MAX
== 65535, "");
172 static_assert(UINT32_MAX
== 4294967295U, "");
173 static_assert(UINT64_MAX
== 18446744073709551615ULL, "");
176 static_assert(INT_FAST8_MIN
<= -128, "");
177 static_assert(INT_FAST16_MIN
<= -32768, "");
178 static_assert(INT_FAST32_MIN
<= -2147483647 - 1, "");
179 static_assert(INT_FAST64_MIN
<= -9223372036854775807LL - 1, "");
182 static_assert(INT_FAST8_MAX
>= 127, "");
183 static_assert(INT_FAST16_MAX
>= 32767, "");
184 static_assert(INT_FAST32_MAX
>= 2147483647, "");
185 static_assert(INT_FAST64_MAX
>= 9223372036854775807LL, "");
188 static_assert(UINT_FAST8_MAX
>= 255, "");
189 static_assert(UINT_FAST16_MAX
>= 65535, "");
190 static_assert(UINT_FAST32_MAX
>= 4294967295U, "");
191 static_assert(UINT_FAST64_MAX
>= 18446744073709551615ULL, "");
194 assert(INTPTR_MIN
== std::numeric_limits
<intptr_t>::min());
197 assert(INTPTR_MAX
== std::numeric_limits
<intptr_t>::max());
200 assert(UINTPTR_MAX
== std::numeric_limits
<uintptr_t>::max());
203 assert(INTMAX_MIN
== std::numeric_limits
<intmax_t>::min());
206 assert(INTMAX_MAX
== std::numeric_limits
<intmax_t>::max());
209 assert(UINTMAX_MAX
== std::numeric_limits
<uintmax_t>::max());
212 assert(PTRDIFF_MIN
== std::numeric_limits
<std::ptrdiff_t>::min());
215 assert(PTRDIFF_MAX
== std::numeric_limits
<std::ptrdiff_t>::max());
218 assert(SIG_ATOMIC_MIN
== std::numeric_limits
<sig_atomic_t>::min());
221 assert(SIG_ATOMIC_MAX
== std::numeric_limits
<sig_atomic_t>::max());
224 assert(SIZE_MAX
== std::numeric_limits
<size_t>::max());
226 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
228 assert(WCHAR_MIN
== std::numeric_limits
<wchar_t>::min());
231 assert(WCHAR_MAX
== std::numeric_limits
<wchar_t>::max());
234 assert(WINT_MIN
== std::numeric_limits
<wint_t>::min());
237 assert(WINT_MAX
== std::numeric_limits
<wint_t>::max());
241 #error INT8_C not defined
245 #error INT16_C not defined
249 #error INT32_C not defined
253 #error INT64_C not defined
257 #error UINT8_C not defined
261 #error UINT16_C not defined
265 #error UINT32_C not defined
269 #error UINT64_C not defined
273 #error INTMAX_C not defined
277 #error UINTMAX_C not defined