• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 numeric_limits
11 
12 // Specializations shall be provided for each arithmetic type, both floating
13 // point and integer, including bool. The member is_specialized shall be
14 // true for all such specializations of numeric_limits.
15 
16 // Non-arithmetic standard types, such as complex<T> (26.3.2), shall not
17 // have specializations.
18 
19 // From [numeric.limits]:
20 
21 // The value of each member of a specialization of numeric_limits on a cv
22 // -qualified type cv T shall be equal to the value of the corresponding
23 // member of the specialization on the unqualified type T.
24 
25 // More convenient to test it here.
26 
27 #include <limits>
28 #include <complex>
29 
30 template <class T>
test()31 void test()
32 {
33     static_assert(std::numeric_limits<T>::is_specialized,
34                  "std::numeric_limits<T>::is_specialized");
35     static_assert(std::numeric_limits<const T>::is_specialized,
36                  "std::numeric_limits<const T>::is_specialized");
37     static_assert(std::numeric_limits<volatile T>::is_specialized,
38                  "std::numeric_limits<volatile T>::is_specialized");
39     static_assert(std::numeric_limits<const volatile T>::is_specialized,
40                  "std::numeric_limits<const volatile T>::is_specialized");
41 }
42 
main()43 int main()
44 {
45     test<bool>();
46     test<char>();
47     test<wchar_t>();
48 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
49     test<char16_t>();
50     test<char32_t>();
51 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
52     test<signed char>();
53     test<unsigned char>();
54     test<signed short>();
55     test<unsigned short>();
56     test<signed int>();
57     test<unsigned int>();
58     test<signed long>();
59     test<unsigned long>();
60     test<signed long long>();
61     test<unsigned long long>();
62 #ifndef _LIBCPP_HAS_NO_INT128
63     test<__int128_t>();
64     test<__uint128_t>();
65 #endif
66     test<float>();
67     test<double>();
68     test<long double>();
69     static_assert(!std::numeric_limits<std::complex<double> >::is_specialized,
70                  "!std::numeric_limits<std::complex<double> >::is_specialized");
71 }
72