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