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