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