From 66531c998aa76bfb5538a28656b979c268e7b126 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 24 Mar 2025 07:30:45 +0100 Subject: [PATCH] [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. --- libcxx/include/__math/traits.h | 8 +------- libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp | 3 +++ libcxx/test/std/numerics/c.math/signbit.pass.cpp | 3 +++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libcxx/include/__math/traits.h b/libcxx/include/__math/traits.h index 0c96f766a767..550eb393e2d4 100644 --- a/libcxx/include/__math/traits.h +++ b/libcxx/include/__math/traits.h @@ -13,7 +13,6 @@ #include <__type_traits/enable_if.h> #include <__type_traits/is_arithmetic.h> #include <__type_traits/is_integral.h> -#include <__type_traits/is_signed.h> #include <__type_traits/promote.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -51,16 +50,11 @@ template return __builtin_signbit(__x); } -template ::value && is_signed<_A1>::value, int> = 0> +template ::value, int> = 0> [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { return __x < 0; } -template ::value && !is_signed<_A1>::value, int> = 0> -[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { - return false; -} - // isfinite template ::value, int> = 0> diff --git a/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp index aebef0b2e136..1ba0063c1dad 100644 --- a/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp +++ b/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp @@ -12,6 +12,9 @@ // +// GCC warns about signbit comparing `bool_v < 0`, which we're testing +// ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare + #include #include #include diff --git a/libcxx/test/std/numerics/c.math/signbit.pass.cpp b/libcxx/test/std/numerics/c.math/signbit.pass.cpp index b5e63dedf136..46cdfd7cab1f 100644 --- a/libcxx/test/std/numerics/c.math/signbit.pass.cpp +++ b/libcxx/test/std/numerics/c.math/signbit.pass.cpp @@ -14,6 +14,9 @@ // These compilers don't support constexpr `__builtin_signbit` yet. // UNSUPPORTED: clang-18, clang-19, apple-clang-15, apple-clang-16, apple-clang-17 +// GCC warns about signbit comparing `bool_v < 0`, which we're testing +// ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare + // XFAIL: FROZEN-CXX03-HEADERS-FIXME #include