301 lines · cpp
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-exception6//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_CHARACTERS22# include <cwchar>23# include <cwctype>24#endif25 26int main(int, char**)27{28 // typedef std::int8_t29 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_t34 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_t39 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_t44 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_t50 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_t55 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_t60 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_t65 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_t71 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_t76 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_t81 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_t86 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_t92 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_t97 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_t102 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_t107 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_t113 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_t118 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_t123 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_t128 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_t134 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_t139 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_t144 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_t149 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_t155 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_t160 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_t166 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_t171 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_MIN177 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_MAX183 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_MAX189 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_MIN195 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_MAX201 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_MAX207 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_MIN213 assert(INTPTR_MIN == std::numeric_limits<std::intptr_t>::min());214 215 // INTPTR_MAX216 assert(INTPTR_MAX == std::numeric_limits<std::intptr_t>::max());217 218 // UINTPTR_MAX219 assert(UINTPTR_MAX == std::numeric_limits<std::uintptr_t>::max());220 221 // INTMAX_MIN222 assert(INTMAX_MIN == std::numeric_limits<std::intmax_t>::min());223 224 // INTMAX_MAX225 assert(INTMAX_MAX == std::numeric_limits<std::intmax_t>::max());226 227 // UINTMAX_MAX228 assert(UINTMAX_MAX == std::numeric_limits<std::uintmax_t>::max());229 230 // PTRDIFF_MIN231 assert(PTRDIFF_MIN == std::numeric_limits<std::ptrdiff_t>::min());232 233 // PTRDIFF_MAX234 assert(PTRDIFF_MAX == std::numeric_limits<std::ptrdiff_t>::max());235 236 // SIG_ATOMIC_MIN237 assert(SIG_ATOMIC_MIN == std::numeric_limits<std::sig_atomic_t>::min());238 239 // SIG_ATOMIC_MAX240 assert(SIG_ATOMIC_MAX == std::numeric_limits<std::sig_atomic_t>::max());241 242 // SIZE_MAX243 assert(SIZE_MAX == std::numeric_limits<std::size_t>::max());244 245#ifndef TEST_HAS_NO_WIDE_CHARACTERS246 // WCHAR_MIN247 assert(WCHAR_MIN == std::numeric_limits<wchar_t>::min());248 249 // WCHAR_MAX250 assert(WCHAR_MAX == std::numeric_limits<wchar_t>::max());251 252 // WINT_MIN253 assert(WINT_MIN == std::numeric_limits<std::wint_t>::min());254 255 // WINT_MAX256 assert(WINT_MAX == std::numeric_limits<std::wint_t>::max());257#endif258 259#ifndef INT8_C260#error INT8_C not defined261#endif262 263#ifndef INT16_C264#error INT16_C not defined265#endif266 267#ifndef INT32_C268#error INT32_C not defined269#endif270 271#ifndef INT64_C272#error INT64_C not defined273#endif274 275#ifndef UINT8_C276#error UINT8_C not defined277#endif278 279#ifndef UINT16_C280#error UINT16_C not defined281#endif282 283#ifndef UINT32_C284#error UINT32_C not defined285#endif286 287#ifndef UINT64_C288#error UINT64_C not defined289#endif290 291#ifndef INTMAX_C292#error INTMAX_C not defined293#endif294 295#ifndef UINTMAX_C296#error UINTMAX_C not defined297#endif298 299 return 0;300}301