1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 // test <cstdint>
10
11 #include <cstdint>
12 #include <cstddef>
13 #include <csignal>
14 #include <climits>
15 #include <type_traits>
16 #include <limits>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
22 # include <cwchar>
23 # include <cwctype>
24 #endif
25
main(int,char **)26 int main(int, char**)
27 {
28 // typedef std::int8_t
29 static_assert(sizeof(std::int8_t)*CHAR_BIT == 8,
30 "sizeof(std::int8_t)*CHAR_BIT == 8");
31 static_assert(std::is_signed<std::int8_t>::value,
32 "std::is_signed<std::int8_t>::value");
33 // typedef std::int16_t
34 static_assert(sizeof(std::int16_t)*CHAR_BIT == 16,
35 "sizeof(std::int16_t)*CHAR_BIT == 16");
36 static_assert(std::is_signed<std::int16_t>::value,
37 "std::is_signed<std::int16_t>::value");
38 // typedef std::int32_t
39 static_assert(sizeof(std::int32_t)*CHAR_BIT == 32,
40 "sizeof(std::int32_t)*CHAR_BIT == 32");
41 static_assert(std::is_signed<std::int32_t>::value,
42 "std::is_signed<std::int32_t>::value");
43 // typedef std::int64_t
44 static_assert(sizeof(std::int64_t)*CHAR_BIT == 64,
45 "sizeof(std::int64_t)*CHAR_BIT == 64");
46 static_assert(std::is_signed<std::int64_t>::value,
47 "std::is_signed<std::int64_t>::value");
48
49 // typedef std::uint8_t
50 static_assert(sizeof(std::uint8_t)*CHAR_BIT == 8,
51 "sizeof(std::uint8_t)*CHAR_BIT == 8");
52 static_assert(std::is_unsigned<std::uint8_t>::value,
53 "std::is_unsigned<std::uint8_t>::value");
54 // typedef std::uint16_t
55 static_assert(sizeof(std::uint16_t)*CHAR_BIT == 16,
56 "sizeof(std::uint16_t)*CHAR_BIT == 16");
57 static_assert(std::is_unsigned<std::uint16_t>::value,
58 "std::is_unsigned<std::uint16_t>::value");
59 // typedef std::uint32_t
60 static_assert(sizeof(std::uint32_t)*CHAR_BIT == 32,
61 "sizeof(std::uint32_t)*CHAR_BIT == 32");
62 static_assert(std::is_unsigned<std::uint32_t>::value,
63 "std::is_unsigned<std::uint32_t>::value");
64 // typedef std::uint64_t
65 static_assert(sizeof(std::uint64_t)*CHAR_BIT == 64,
66 "sizeof(std::uint64_t)*CHAR_BIT == 64");
67 static_assert(std::is_unsigned<std::uint64_t>::value,
68 "std::is_unsigned<std::uint64_t>::value");
69
70 // typedef std::int_least8_t
71 static_assert(sizeof(std::int_least8_t)*CHAR_BIT >= 8,
72 "sizeof(std::int_least8_t)*CHAR_BIT >= 8");
73 static_assert(std::is_signed<std::int_least8_t>::value,
74 "std::is_signed<std::int_least8_t>::value");
75 // typedef std::int_least16_t
76 static_assert(sizeof(std::int_least16_t)*CHAR_BIT >= 16,
77 "sizeof(std::int_least16_t)*CHAR_BIT >= 16");
78 static_assert(std::is_signed<std::int_least16_t>::value,
79 "std::is_signed<std::int_least16_t>::value");
80 // typedef std::int_least32_t
81 static_assert(sizeof(std::int_least32_t)*CHAR_BIT >= 32,
82 "sizeof(std::int_least32_t)*CHAR_BIT >= 32");
83 static_assert(std::is_signed<std::int_least32_t>::value,
84 "std::is_signed<std::int_least32_t>::value");
85 // typedef std::int_least64_t
86 static_assert(sizeof(std::int_least64_t)*CHAR_BIT >= 64,
87 "sizeof(std::int_least64_t)*CHAR_BIT >= 64");
88 static_assert(std::is_signed<std::int_least64_t>::value,
89 "std::is_signed<std::int_least64_t>::value");
90
91 // typedef std::uint_least8_t
92 static_assert(sizeof(std::uint_least8_t)*CHAR_BIT >= 8,
93 "sizeof(std::uint_least8_t)*CHAR_BIT >= 8");
94 static_assert(std::is_unsigned<std::uint_least8_t>::value,
95 "std::is_unsigned<std::uint_least8_t>::value");
96 // typedef std::uint_least16_t
97 static_assert(sizeof(std::uint_least16_t)*CHAR_BIT >= 16,
98 "sizeof(std::uint_least16_t)*CHAR_BIT >= 16");
99 static_assert(std::is_unsigned<std::uint_least16_t>::value,
100 "std::is_unsigned<std::uint_least16_t>::value");
101 // typedef std::uint_least32_t
102 static_assert(sizeof(std::uint_least32_t)*CHAR_BIT >= 32,
103 "sizeof(std::uint_least32_t)*CHAR_BIT >= 32");
104 static_assert(std::is_unsigned<std::uint_least32_t>::value,
105 "std::is_unsigned<std::uint_least32_t>::value");
106 // typedef std::uint_least64_t
107 static_assert(sizeof(std::uint_least64_t)*CHAR_BIT >= 64,
108 "sizeof(std::uint_least64_t)*CHAR_BIT >= 64");
109 static_assert(std::is_unsigned<std::uint_least64_t>::value,
110 "std::is_unsigned<std::uint_least64_t>::value");
111
112 // typedef std::int_fast8_t
113 static_assert(sizeof(std::int_fast8_t)*CHAR_BIT >= 8,
114 "sizeof(std::int_fast8_t)*CHAR_BIT >= 8");
115 static_assert(std::is_signed<std::int_fast8_t>::value,
116 "std::is_signed<std::int_fast8_t>::value");
117 // typedef std::int_fast16_t
118 static_assert(sizeof(std::int_fast16_t)*CHAR_BIT >= 16,
119 "sizeof(std::int_fast16_t)*CHAR_BIT >= 16");
120 static_assert(std::is_signed<std::int_fast16_t>::value,
121 "std::is_signed<std::int_fast16_t>::value");
122 // typedef std::int_fast32_t
123 static_assert(sizeof(std::int_fast32_t)*CHAR_BIT >= 32,
124 "sizeof(std::int_fast32_t)*CHAR_BIT >= 32");
125 static_assert(std::is_signed<std::int_fast32_t>::value,
126 "std::is_signed<std::int_fast32_t>::value");
127 // typedef std::int_fast64_t
128 static_assert(sizeof(std::int_fast64_t)*CHAR_BIT >= 64,
129 "sizeof(std::int_fast64_t)*CHAR_BIT >= 64");
130 static_assert(std::is_signed<std::int_fast64_t>::value,
131 "std::is_signed<std::int_fast64_t>::value");
132
133 // typedef std::uint_fast8_t
134 static_assert(sizeof(std::uint_fast8_t)*CHAR_BIT >= 8,
135 "sizeof(std::uint_fast8_t)*CHAR_BIT >= 8");
136 static_assert(std::is_unsigned<std::uint_fast8_t>::value,
137 "std::is_unsigned<std::uint_fast8_t>::value");
138 // typedef std::uint_fast16_t
139 static_assert(sizeof(std::uint_fast16_t)*CHAR_BIT >= 16,
140 "sizeof(std::uint_fast16_t)*CHAR_BIT >= 16");
141 static_assert(std::is_unsigned<std::uint_fast16_t>::value,
142 "std::is_unsigned<std::uint_fast16_t>::value");
143 // typedef std::uint_fast32_t
144 static_assert(sizeof(std::uint_fast32_t)*CHAR_BIT >= 32,
145 "sizeof(std::uint_fast32_t)*CHAR_BIT >= 32");
146 static_assert(std::is_unsigned<std::uint_fast32_t>::value,
147 "std::is_unsigned<std::uint_fast32_t>::value");
148 // typedef std::uint_fast64_t
149 static_assert(sizeof(std::uint_fast64_t)*CHAR_BIT >= 64,
150 "sizeof(std::uint_fast64_t)*CHAR_BIT >= 64");
151 static_assert(std::is_unsigned<std::uint_fast64_t>::value,
152 "std::is_unsigned<std::uint_fast64_t>::value");
153
154 // typedef std::intptr_t
155 static_assert(sizeof(std::intptr_t) >= sizeof(void*),
156 "sizeof(std::intptr_t) >= sizeof(void*)");
157 static_assert(std::is_signed<std::intptr_t>::value,
158 "std::is_signed<std::intptr_t>::value");
159 // typedef std::uintptr_t
160 static_assert(sizeof(std::uintptr_t) >= sizeof(void*),
161 "sizeof(std::uintptr_t) >= sizeof(void*)");
162 static_assert(std::is_unsigned<std::uintptr_t>::value,
163 "std::is_unsigned<std::uintptr_t>::value");
164
165 // typedef std::intmax_t
166 static_assert(sizeof(std::intmax_t) >= sizeof(long long),
167 "sizeof(std::intmax_t) >= sizeof(long long)");
168 static_assert(std::is_signed<std::intmax_t>::value,
169 "std::is_signed<std::intmax_t>::value");
170 // typedef std::uintmax_t
171 static_assert(sizeof(std::uintmax_t) >= sizeof(unsigned long long),
172 "sizeof(std::uintmax_t) >= sizeof(unsigned long long)");
173 static_assert(std::is_unsigned<std::uintmax_t>::value,
174 "std::is_unsigned<std::uintmax_t>::value");
175
176 // INTN_MIN
177 static_assert(INT8_MIN == -128, "INT8_MIN == -128");
178 static_assert(INT16_MIN == -32768, "INT16_MIN == -32768");
179 static_assert(INT32_MIN == -2147483647 - 1, "INT32_MIN == -2147483648");
180 static_assert(INT64_MIN == -9223372036854775807LL - 1, "INT64_MIN == -9223372036854775808LL");
181
182 // INTN_MAX
183 static_assert(INT8_MAX == 127, "INT8_MAX == 127");
184 static_assert(INT16_MAX == 32767, "INT16_MAX == 32767");
185 static_assert(INT32_MAX == 2147483647, "INT32_MAX == 2147483647");
186 static_assert(INT64_MAX == 9223372036854775807LL, "INT64_MAX == 9223372036854775807LL");
187
188 // UINTN_MAX
189 static_assert(UINT8_MAX == 255, "UINT8_MAX == 255");
190 static_assert(UINT16_MAX == 65535, "UINT16_MAX == 65535");
191 static_assert(UINT32_MAX == 4294967295U, "UINT32_MAX == 4294967295");
192 static_assert(UINT64_MAX == 18446744073709551615ULL, "UINT64_MAX == 18446744073709551615ULL");
193
194 // INT_FASTN_MIN
195 static_assert(INT_FAST8_MIN <= -128, "INT_FAST8_MIN <= -128");
196 static_assert(INT_FAST16_MIN <= -32768, "INT_FAST16_MIN <= -32768");
197 static_assert(INT_FAST32_MIN <= -2147483647 - 1, "INT_FAST32_MIN <= -2147483648");
198 static_assert(INT_FAST64_MIN <= -9223372036854775807LL - 1, "INT_FAST64_MIN <= -9223372036854775808LL");
199
200 // INT_FASTN_MAX
201 static_assert(INT_FAST8_MAX >= 127, "INT_FAST8_MAX >= 127");
202 static_assert(INT_FAST16_MAX >= 32767, "INT_FAST16_MAX >= 32767");
203 static_assert(INT_FAST32_MAX >= 2147483647, "INT_FAST32_MAX >= 2147483647");
204 static_assert(INT_FAST64_MAX >= 9223372036854775807LL, "INT_FAST64_MAX >= 9223372036854775807LL");
205
206 // UINT_FASTN_MAX
207 static_assert(UINT_FAST8_MAX >= 255, "UINT_FAST8_MAX >= 255");
208 static_assert(UINT_FAST16_MAX >= 65535, "UINT_FAST16_MAX >= 65535");
209 static_assert(UINT_FAST32_MAX >= 4294967295U, "UINT_FAST32_MAX >= 4294967295");
210 static_assert(UINT_FAST64_MAX >= 18446744073709551615ULL, "UINT_FAST64_MAX >= 18446744073709551615ULL");
211
212 // INTPTR_MIN
213 assert(INTPTR_MIN == std::numeric_limits<std::intptr_t>::min());
214
215 // INTPTR_MAX
216 assert(INTPTR_MAX == std::numeric_limits<std::intptr_t>::max());
217
218 // UINTPTR_MAX
219 assert(UINTPTR_MAX == std::numeric_limits<std::uintptr_t>::max());
220
221 // INTMAX_MIN
222 assert(INTMAX_MIN == std::numeric_limits<std::intmax_t>::min());
223
224 // INTMAX_MAX
225 assert(INTMAX_MAX == std::numeric_limits<std::intmax_t>::max());
226
227 // UINTMAX_MAX
228 assert(UINTMAX_MAX == std::numeric_limits<std::uintmax_t>::max());
229
230 // PTRDIFF_MIN
231 assert(PTRDIFF_MIN == std::numeric_limits<std::ptrdiff_t>::min());
232
233 // PTRDIFF_MAX
234 assert(PTRDIFF_MAX == std::numeric_limits<std::ptrdiff_t>::max());
235
236 // SIG_ATOMIC_MIN
237 assert(SIG_ATOMIC_MIN == std::numeric_limits<std::sig_atomic_t>::min());
238
239 // SIG_ATOMIC_MAX
240 assert(SIG_ATOMIC_MAX == std::numeric_limits<std::sig_atomic_t>::max());
241
242 // SIZE_MAX
243 assert(SIZE_MAX == std::numeric_limits<std::size_t>::max());
244
245 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
246 // WCHAR_MIN
247 assert(WCHAR_MIN == std::numeric_limits<wchar_t>::min());
248
249 // WCHAR_MAX
250 assert(WCHAR_MAX == std::numeric_limits<wchar_t>::max());
251
252 // WINT_MIN
253 assert(WINT_MIN == std::numeric_limits<std::wint_t>::min());
254
255 // WINT_MAX
256 assert(WINT_MAX == std::numeric_limits<std::wint_t>::max());
257 #endif
258
259 #ifndef INT8_C
260 #error INT8_C not defined
261 #endif
262
263 #ifndef INT16_C
264 #error INT16_C not defined
265 #endif
266
267 #ifndef INT32_C
268 #error INT32_C not defined
269 #endif
270
271 #ifndef INT64_C
272 #error INT64_C not defined
273 #endif
274
275 #ifndef UINT8_C
276 #error UINT8_C not defined
277 #endif
278
279 #ifndef UINT16_C
280 #error UINT16_C not defined
281 #endif
282
283 #ifndef UINT32_C
284 #error UINT32_C not defined
285 #endif
286
287 #ifndef UINT64_C
288 #error UINT64_C not defined
289 #endif
290
291 #ifndef INTMAX_C
292 #error INTMAX_C not defined
293 #endif
294
295 #ifndef UINTMAX_C
296 #error UINTMAX_C not defined
297 #endif
298
299 return 0;
300 }
301