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