Home | History | Annotate | Download | only in depr.c.headers
      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 <stdint.h>
     11 
     12 #include <stdint.h>
     13 #include <csignal>
     14 #include <cwctype>
     15 #include <climits>
     16 #include <type_traits>
     17 #include <limits>
     18 #include <cassert>
     19 
     20 int main()
     21 {
     22     // typedef int8_t
     23     static_assert(sizeof(int8_t)*CHAR_BIT == 8,
     24                  "sizeof(int8_t)*CHAR_BIT == 8");
     25     static_assert(std::is_signed<int8_t>::value,
     26                  "std::is_signed<int8_t>::value");
     27     // typedef int16_t
     28     static_assert(sizeof(int16_t)*CHAR_BIT == 16,
     29                  "sizeof(int16_t)*CHAR_BIT == 16");
     30     static_assert(std::is_signed<int16_t>::value,
     31                  "std::is_signed<int16_t>::value");
     32     // typedef int32_t
     33     static_assert(sizeof(int32_t)*CHAR_BIT == 32,
     34                  "sizeof(int32_t)*CHAR_BIT == 32");
     35     static_assert(std::is_signed<int32_t>::value,
     36                  "std::is_signed<int32_t>::value");
     37     // typedef int64_t
     38     static_assert(sizeof(int64_t)*CHAR_BIT == 64,
     39                  "sizeof(int64_t)*CHAR_BIT == 64");
     40     static_assert(std::is_signed<int64_t>::value,
     41                  "std::is_signed<int64_t>::value");
     42 
     43     // typedef uint8_t
     44     static_assert(sizeof(uint8_t)*CHAR_BIT == 8,
     45                  "sizeof(uint8_t)*CHAR_BIT == 8");
     46     static_assert(std::is_unsigned<uint8_t>::value,
     47                  "std::is_unsigned<uint8_t>::value");
     48     // typedef uint16_t
     49     static_assert(sizeof(uint16_t)*CHAR_BIT == 16,
     50                  "sizeof(uint16_t)*CHAR_BIT == 16");
     51     static_assert(std::is_unsigned<uint16_t>::value,
     52                  "std::is_unsigned<uint16_t>::value");
     53     // typedef uint32_t
     54     static_assert(sizeof(uint32_t)*CHAR_BIT == 32,
     55                  "sizeof(uint32_t)*CHAR_BIT == 32");
     56     static_assert(std::is_unsigned<uint32_t>::value,
     57                  "std::is_unsigned<uint32_t>::value");
     58     // typedef uint64_t
     59     static_assert(sizeof(uint64_t)*CHAR_BIT == 64,
     60                  "sizeof(uint64_t)*CHAR_BIT == 64");
     61     static_assert(std::is_unsigned<uint64_t>::value,
     62                  "std::is_unsigned<uint64_t>::value");
     63 
     64     // typedef int_least8_t
     65     static_assert(sizeof(int_least8_t)*CHAR_BIT >= 8,
     66                  "sizeof(int_least8_t)*CHAR_BIT >= 8");
     67     static_assert(std::is_signed<int_least8_t>::value,
     68                  "std::is_signed<int_least8_t>::value");
     69     // typedef int_least16_t
     70     static_assert(sizeof(int_least16_t)*CHAR_BIT >= 16,
     71                  "sizeof(int_least16_t)*CHAR_BIT >= 16");
     72     static_assert(std::is_signed<int_least16_t>::value,
     73                  "std::is_signed<int_least16_t>::value");
     74     // typedef int_least32_t
     75     static_assert(sizeof(int_least32_t)*CHAR_BIT >= 32,
     76                  "sizeof(int_least32_t)*CHAR_BIT >= 32");
     77     static_assert(std::is_signed<int_least32_t>::value,
     78                  "std::is_signed<int_least32_t>::value");
     79     // typedef int_least64_t
     80     static_assert(sizeof(int_least64_t)*CHAR_BIT >= 64,
     81                  "sizeof(int_least64_t)*CHAR_BIT >= 64");
     82     static_assert(std::is_signed<int_least64_t>::value,
     83                  "std::is_signed<int_least64_t>::value");
     84 
     85     // typedef uint_least8_t
     86     static_assert(sizeof(uint_least8_t)*CHAR_BIT >= 8,
     87                  "sizeof(uint_least8_t)*CHAR_BIT >= 8");
     88     static_assert(std::is_unsigned<uint_least8_t>::value,
     89                  "std::is_unsigned<uint_least8_t>::value");
     90     // typedef uint_least16_t
     91     static_assert(sizeof(uint_least16_t)*CHAR_BIT >= 16,
     92                  "sizeof(uint_least16_t)*CHAR_BIT >= 16");
     93     static_assert(std::is_unsigned<uint_least16_t>::value,
     94                  "std::is_unsigned<uint_least16_t>::value");
     95     // typedef uint_least32_t
     96     static_assert(sizeof(uint_least32_t)*CHAR_BIT >= 32,
     97                  "sizeof(uint_least32_t)*CHAR_BIT >= 32");
     98     static_assert(std::is_unsigned<uint_least32_t>::value,
     99                  "std::is_unsigned<uint_least32_t>::value");
    100     // typedef uint_least64_t
    101     static_assert(sizeof(uint_least64_t)*CHAR_BIT >= 64,
    102                  "sizeof(uint_least64_t)*CHAR_BIT >= 64");
    103     static_assert(std::is_unsigned<uint_least64_t>::value,
    104                  "std::is_unsigned<uint_least64_t>::value");
    105 
    106     // typedef int_fast8_t
    107     static_assert(sizeof(int_fast8_t)*CHAR_BIT >= 8,
    108                  "sizeof(int_fast8_t)*CHAR_BIT >= 8");
    109     static_assert(std::is_signed<int_fast8_t>::value,
    110                  "std::is_signed<int_fast8_t>::value");
    111     // typedef int_fast16_t
    112     static_assert(sizeof(int_fast16_t)*CHAR_BIT >= 16,
    113                  "sizeof(int_fast16_t)*CHAR_BIT >= 16");
    114     static_assert(std::is_signed<int_fast16_t>::value,
    115                  "std::is_signed<int_fast16_t>::value");
    116     // typedef int_fast32_t
    117     static_assert(sizeof(int_fast32_t)*CHAR_BIT >= 32,
    118                  "sizeof(int_fast32_t)*CHAR_BIT >= 32");
    119     static_assert(std::is_signed<int_fast32_t>::value,
    120                  "std::is_signed<int_fast32_t>::value");
    121     // typedef int_fast64_t
    122     static_assert(sizeof(int_fast64_t)*CHAR_BIT >= 64,
    123                  "sizeof(int_fast64_t)*CHAR_BIT >= 64");
    124     static_assert(std::is_signed<int_fast64_t>::value,
    125                  "std::is_signed<int_fast64_t>::value");
    126 
    127     // typedef uint_fast8_t
    128     static_assert(sizeof(uint_fast8_t)*CHAR_BIT >= 8,
    129                  "sizeof(uint_fast8_t)*CHAR_BIT >= 8");
    130     static_assert(std::is_unsigned<uint_fast8_t>::value,
    131                  "std::is_unsigned<uint_fast8_t>::value");
    132     // typedef uint_fast16_t
    133     static_assert(sizeof(uint_fast16_t)*CHAR_BIT >= 16,
    134                  "sizeof(uint_fast16_t)*CHAR_BIT >= 16");
    135     static_assert(std::is_unsigned<uint_fast16_t>::value,
    136                  "std::is_unsigned<uint_fast16_t>::value");
    137     // typedef uint_fast32_t
    138     static_assert(sizeof(uint_fast32_t)*CHAR_BIT >= 32,
    139                  "sizeof(uint_fast32_t)*CHAR_BIT >= 32");
    140     static_assert(std::is_unsigned<uint_fast32_t>::value,
    141                  "std::is_unsigned<uint_fast32_t>::value");
    142     // typedef uint_fast64_t
    143     static_assert(sizeof(uint_fast64_t)*CHAR_BIT >= 64,
    144                  "sizeof(uint_fast64_t)*CHAR_BIT >= 64");
    145     static_assert(std::is_unsigned<uint_fast64_t>::value,
    146                  "std::is_unsigned<uint_fast64_t>::value");
    147 
    148     // typedef intptr_t
    149     static_assert(sizeof(intptr_t) >= sizeof(void*),
    150                  "sizeof(intptr_t) >= sizeof(void*)");
    151     static_assert(std::is_signed<intptr_t>::value,
    152                  "std::is_signed<intptr_t>::value");
    153     // typedef uintptr_t
    154     static_assert(sizeof(uintptr_t) >= sizeof(void*),
    155                  "sizeof(uintptr_t) >= sizeof(void*)");
    156     static_assert(std::is_unsigned<uintptr_t>::value,
    157                  "std::is_unsigned<uintptr_t>::value");
    158 
    159     // typedef intmax_t
    160     static_assert(sizeof(intmax_t) >= sizeof(long long),
    161                  "sizeof(intmax_t) >= sizeof(long long)");
    162     static_assert(std::is_signed<intmax_t>::value,
    163                  "std::is_signed<intmax_t>::value");
    164     // typedef uintmax_t
    165     static_assert(sizeof(uintmax_t) >= sizeof(unsigned long long),
    166                  "sizeof(uintmax_t) >= sizeof(unsigned long long)");
    167     static_assert(std::is_unsigned<uintmax_t>::value,
    168                  "std::is_unsigned<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<intptr_t>::min());
    208 
    209     // INTPTR_MAX
    210     assert(INTPTR_MAX == std::numeric_limits<intptr_t>::max());
    211 
    212     // UINTPTR_MAX
    213     assert(UINTPTR_MAX == std::numeric_limits<uintptr_t>::max());
    214 
    215     // INTMAX_MIN
    216     assert(INTMAX_MIN == std::numeric_limits<intmax_t>::min());
    217 
    218     // INTMAX_MAX
    219     assert(INTMAX_MAX == std::numeric_limits<intmax_t>::max());
    220 
    221     // UINTMAX_MAX
    222     assert(UINTMAX_MAX == std::numeric_limits<uintmax_t>::max());
    223 
    224     // PTRDIFF_MIN
    225     assert(PTRDIFF_MIN == std::numeric_limits<ptrdiff_t>::min());
    226 
    227     // PTRDIFF_MAX
    228     assert(PTRDIFF_MAX == std::numeric_limits<ptrdiff_t>::max());
    229 
    230     // SIG_ATOMIC_MIN
    231     assert(SIG_ATOMIC_MIN == std::numeric_limits<sig_atomic_t>::min());
    232 
    233     // SIG_ATOMIC_MAX
    234     assert(SIG_ATOMIC_MAX == std::numeric_limits<sig_atomic_t>::max());
    235 
    236     // SIZE_MAX
    237     assert(SIZE_MAX == std::numeric_limits<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<wint_t>::min());
    247 
    248     // WINT_MAX
    249     assert(WINT_MAX == std::numeric_limits<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 }
    291