Skip to content

Commit 5ceea95

Browse files
committed
Prefer libcxx overload
By using `_LIBCPP_PREFERRED_OVERLOAD` we make sure that a given overload is a better match than an otherwise equally good function declaration. Why is there an equally good function declaration in the first place? Underlying the Windows SDK is the UCRT, the universal C runtime, which clang-cl makes use of. The UCRT should provide only C library headers, but does on top comes with overloads for all cv-unqualified floating point types (float, double, long double) for `std::signbit()` in https://github.com/microsoft/win32metadata/blob/e012b29924c53aa941fc010850b68331b0c3ea80/generation/WinSDK/RecompiledIdlHeaders/ucrt/corecrt_math.h#L309-L322. In a certain way, this can be seen as a deviation from the C standard. We need to work around it.
1 parent 1b3890c commit 5ceea95

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

libcxx/include/__math/traits.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
3838
#endif
3939
}
4040

41-
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT {
41+
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
42+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
43+
_LIBCPP_PREFERRED_OVERLOAD
44+
#endif
45+
bool
46+
signbit(float __x) _NOEXCEPT {
4247
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
4348
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
4449
return __builtin_copysign(1.0, __x) == -1.0;
@@ -47,7 +52,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
4752
#endif
4853
}
4954

50-
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT {
55+
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
56+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
57+
_LIBCPP_PREFERRED_OVERLOAD
58+
#endif
59+
bool
60+
signbit(double __x) _NOEXCEPT {
5161
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
5262
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
5363
return __builtin_copysign(1.0, __x) == -1.0;
@@ -56,7 +66,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
5666
#endif
5767
}
5868

59-
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT {
69+
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
70+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
71+
_LIBCPP_PREFERRED_OVERLOAD
72+
#endif
73+
bool
74+
signbit(long double __x) _NOEXCEPT {
6075
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
6176
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
6277
return __builtin_copysign(1.0, __x) == -1.0;

0 commit comments

Comments
 (0)