Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // test numeric_limits |
| 11 | |
| 12 | // traps |
| 13 | |
| 14 | #include <limits> |
| 15 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 16 | #if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) |
Marshall Clow | 13fbe9d | 2014-02-03 23:26:56 +0000 | [diff] [blame] | 17 | static const bool integral_types_trap = true; |
| 18 | #else |
| 19 | static const bool integral_types_trap = false; |
| 20 | #endif |
| 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | template <class T, bool expected> |
| 23 | void |
| 24 | test() |
| 25 | { |
| 26 | static_assert(std::numeric_limits<T>::traps == expected, "traps test 1"); |
| 27 | static_assert(std::numeric_limits<const T>::traps == expected, "traps test 2"); |
| 28 | static_assert(std::numeric_limits<volatile T>::traps == expected, "traps test 3"); |
| 29 | static_assert(std::numeric_limits<const volatile T>::traps == expected, "traps test 4"); |
| 30 | } |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | test<bool, false>(); |
Marshall Clow | 13fbe9d | 2014-02-03 23:26:56 +0000 | [diff] [blame] | 35 | test<char, integral_types_trap>(); |
| 36 | test<signed char, integral_types_trap>(); |
| 37 | test<unsigned char, integral_types_trap>(); |
| 38 | test<wchar_t, integral_types_trap>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
Marshall Clow | 13fbe9d | 2014-02-03 23:26:56 +0000 | [diff] [blame] | 40 | test<char16_t, integral_types_trap>(); |
| 41 | test<char32_t, integral_types_trap>(); |
Howard Hinnant | cf6dcc3 | 2010-08-22 00:31:12 +0000 | [diff] [blame] | 42 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Marshall Clow | 13fbe9d | 2014-02-03 23:26:56 +0000 | [diff] [blame] | 43 | test<short, integral_types_trap>(); |
| 44 | test<unsigned short, integral_types_trap>(); |
| 45 | test<int, integral_types_trap>(); |
| 46 | test<unsigned int, integral_types_trap>(); |
| 47 | test<long, integral_types_trap>(); |
| 48 | test<unsigned long, integral_types_trap>(); |
| 49 | test<long long, integral_types_trap>(); |
| 50 | test<unsigned long long, integral_types_trap>(); |
Stephan Tolksdorf | 8a71d23 | 2014-03-26 19:45:52 +0000 | [diff] [blame] | 51 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 52 | test<__int128_t, integral_types_trap>(); |
| 53 | test<__uint128_t, integral_types_trap>(); |
| 54 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | test<float, false>(); |
| 56 | test<double, false>(); |
| 57 | test<long double, false>(); |
| 58 | } |