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