cstdint.pass.cpp 12 KB

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