Skip to content

Commit 33f9f32

Browse files
[libc++] Make std::numeric_limits<NonPromoted>::traps false
Per [LWG554](https://cplusplus.github.io/LWG/issue554), the rationale is that even if `true / false` traps, the values causing trap are the converted `int` values produced by usual arithmetic conversion, but not the original `bool` values. This is also true for all other non-promoted integer types. As a result, `std::numeric_limits<I>` should be `false` if `I` is a non non-promoted integer type.
1 parent 9f5811e commit 33f9f32

File tree

2 files changed

+11
-10
lines changed
  • libcxx

2 files changed

+11
-10
lines changed

libcxx/include/limits

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ template<> class numeric_limits<cv long double>;
107107
#else
108108
# include <__config>
109109
# include <__type_traits/is_arithmetic.h>
110+
# include <__type_traits/is_same.h>
110111
# include <__type_traits/is_signed.h>
111112

112113
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -220,7 +221,7 @@ protected:
220221
static _LIBCPP_CONSTEXPR const bool is_modulo = !std::is_signed<_Tp>::value;
221222

222223
# if defined(__i386__) || defined(__x86_64__) || defined(__wasm__)
223-
static _LIBCPP_CONSTEXPR const bool traps = true;
224+
static _LIBCPP_CONSTEXPR const bool traps = is_same<decltype(+_Tp(0)), _Tp>::value;
224225
# else
225226
static _LIBCPP_CONSTEXPR const bool traps = false;
226227
# endif

libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/traps.pass.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ test()
3333
int main(int, char**)
3434
{
3535
test<bool, false>();
36-
test<char, integral_types_trap>();
37-
test<signed char, integral_types_trap>();
38-
test<unsigned char, integral_types_trap>();
39-
test<wchar_t, integral_types_trap>();
36+
test<char, false>();
37+
test<signed char, false>();
38+
test<unsigned char, false>();
39+
test<wchar_t, false>();
4040
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
41-
test<char8_t, integral_types_trap>();
41+
test<char8_t, false>();
4242
#endif
43-
test<char16_t, integral_types_trap>();
44-
test<char32_t, integral_types_trap>();
45-
test<short, integral_types_trap>();
46-
test<unsigned short, integral_types_trap>();
43+
test<char16_t, false>();
44+
test<char32_t, false>();
45+
test<short, false>();
46+
test<unsigned short, false>();
4747
test<int, integral_types_trap>();
4848
test<unsigned int, integral_types_trap>();
4949
test<long, integral_types_trap>();

0 commit comments

Comments
 (0)