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 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 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 #ifndef TEST_HAS_NO_UNICODE_CHARS 45 test<char16_t, integral_types_trap>(); 46 test<char32_t, integral_types_trap>(); 47 #endif 48 test<short, integral_types_trap>(); 49 test<unsigned short, integral_types_trap>(); 50 test<int, integral_types_trap>(); 51 test<unsigned int, integral_types_trap>(); 52 test<long, integral_types_trap>(); 53 test<unsigned long, integral_types_trap>(); 54 test<long long, integral_types_trap>(); 55 test<unsigned long long, integral_types_trap>(); 56 #ifndef TEST_HAS_NO_INT128 57 test<__int128_t, integral_types_trap>(); 58 test<__uint128_t, integral_types_trap>(); 59 #endif 60 test<float, false>(); 61 test<double, false>(); 62 test<long double, false>(); 63 64 return 0; 65 } 66