Skip to content

Commit 66531c9

Browse files
authored
[libc++] Remove one of the std::signbit overloads (#130505)
We'e specialized `std::signbit` for signed and unsigned integral types seperately, even though the optimizer can trivially figure out that `unsigned_value < 0` always false is. This patch removes the specialization, since there is really not much of a benefit to it.
1 parent e3bd1f2 commit 66531c9

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

libcxx/include/__math/traits.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__type_traits/enable_if.h>
1414
#include <__type_traits/is_arithmetic.h>
1515
#include <__type_traits/is_integral.h>
16-
#include <__type_traits/is_signed.h>
1716
#include <__type_traits/promote.h>
1817

1918
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -51,16 +50,11 @@ template <class = void>
5150
return __builtin_signbit(__x);
5251
}
5352

54-
template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0>
53+
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
5554
[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
5655
return __x < 0;
5756
}
5857

59-
template <class _A1, __enable_if_t<is_integral<_A1>::value && !is_signed<_A1>::value, int> = 0>
60-
[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
61-
return false;
62-
}
63-
6458
// isfinite
6559

6660
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>

libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
// <math.h>
1414

15+
// GCC warns about signbit comparing `bool_v < 0`, which we're testing
16+
// ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare
17+
1518
#include <math.h>
1619
#include <type_traits>
1720
#include <cassert>

libcxx/test/std/numerics/c.math/signbit.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// These compilers don't support constexpr `__builtin_signbit` yet.
1515
// UNSUPPORTED: clang-18, clang-19, apple-clang-15, apple-clang-16, apple-clang-17
1616

17+
// GCC warns about signbit comparing `bool_v < 0`, which we're testing
18+
// ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare
19+
1720
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
1821

1922
#include <cassert>

0 commit comments

Comments
 (0)