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 // traps
12 
13 #include <limits>
14 
15 #include "test_macros.h"
16 
17 #if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || \
18     defined(__wasm__)
19 static const bool integral_types_trap = true;
20 #else
21 static const bool integral_types_trap = false;
22 #endif
23 
24 template <class T, bool expected>
25 void
test()26 test()
27 {
28     static_assert(std::numeric_limits<T>::traps == expected, "traps test 1");
29     static_assert(std::numeric_limits<const T>::traps == expected, "traps test 2");
30     static_assert(std::numeric_limits<volatile T>::traps == expected, "traps test 3");
31     static_assert(std::numeric_limits<const volatile T>::traps == expected, "traps test 4");
32 }
33 
main(int,char **)34 int main(int, char**)
35 {
36     test<bool, false>();
37     test<char, integral_types_trap>();
38     test<signed char, integral_types_trap>();
39     test<unsigned char, integral_types_trap>();
40     test<wchar_t, integral_types_trap>();
41 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
42     test<char8_t, integral_types_trap>();
43 #endif
44     test<char16_t, integral_types_trap>();
45     test<char32_t, integral_types_trap>();
46     test<short, integral_types_trap>();
47     test<unsigned short, integral_types_trap>();
48     test<int, integral_types_trap>();
49     test<unsigned int, integral_types_trap>();
50     test<long, integral_types_trap>();
51     test<unsigned long, integral_types_trap>();
52     test<long long, integral_types_trap>();
53     test<unsigned long long, integral_types_trap>();
54 #ifndef TEST_HAS_NO_INT128
55     test<__int128_t, integral_types_trap>();
56     test<__uint128_t, integral_types_trap>();
57 #endif
58     test<float, false>();
59     test<double, false>();
60     test<long double, false>();
61 
62   return 0;
63 }
64