[libcxx] r331241 - Fix return type of isinf(double) and isnan(double) where possible.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 30 20:05:40 PDT 2018
Author: rsmith
Date: Mon Apr 30 20:05:40 2018
New Revision: 331241
URL: http://llvm.org/viewvc/llvm-project?rev=331241&view=rev
Log:
Fix return type of isinf(double) and isnan(double) where possible.
When using an old version of glibc, a ::isinf(double) and ::isnan(double)
function is provided, rather than just the macro required by C and C++.
Displace this function using _LIBCPP_PREFERRED_OVERLOAD where possible.
The only remaining case where we should get the wrong return type is now
glibc + libc++ + a non-clang compiler.
Modified:
libcxx/trunk/include/math.h
libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp
Modified: libcxx/trunk/include/math.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/math.h?rev=331241&r1=331240&r2=331241&view=diff
==============================================================================
--- libcxx/trunk/include/math.h (original)
+++ libcxx/trunk/include/math.h Mon Apr 30 20:05:40 2018
@@ -483,6 +483,20 @@ typename std::enable_if<
isinf(_A1) _NOEXCEPT
{ return false; }
+#ifdef _LIBCPP_PREFERRED_OVERLOAD
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isinf(float __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+bool
+isinf(double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isinf(long double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); }
+#endif
+
#endif // isinf
// isnan
@@ -513,6 +527,20 @@ typename std::enable_if<std::is_integral
isnan(_A1) _NOEXCEPT
{ return false; }
+#ifdef _LIBCPP_PREFERRED_OVERLOAD
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isnan(float __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+bool
+isnan(double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isnan(long double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); }
+#endif
+
#endif // isnan
// isnormal
Modified: libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp?rev=331241&r1=331240&r2=331241&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp Mon Apr 30 20:05:40 2018
@@ -661,11 +661,12 @@ void test_isinf()
static_assert((std::is_same<decltype(std::isinf((float)0)), bool>::value), "");
typedef decltype(std::isinf((double)0)) DoubleRetType;
-#ifndef __linux__
+#if !defined(__linux__) || defined(__clang__)
static_assert((std::is_same<DoubleRetType, bool>::value), "");
#else
- // GLIBC < 2.26 defines 'isinf(double)' with a return type of 'int' in
- // all C++ dialects. The test should tolerate this.
+ // GLIBC < 2.23 defines 'isinf(double)' with a return type of 'int' in
+ // all C++ dialects. The test should tolerate this when libc++ can't work
+ // around it.
// See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439
static_assert((std::is_same<DoubleRetType, bool>::value
|| std::is_same<DoubleRetType, int>::value), "");
@@ -746,11 +747,12 @@ void test_isnan()
static_assert((std::is_same<decltype(std::isnan((float)0)), bool>::value), "");
typedef decltype(std::isnan((double)0)) DoubleRetType;
-#ifndef __linux__
+#if !defined(__linux__) || defined(__clang__)
static_assert((std::is_same<DoubleRetType, bool>::value), "");
#else
- // GLIBC < 2.26 defines 'isnan(double)' with a return type of 'int' in
- // all C++ dialects. The test should tolerate this.
+ // GLIBC < 2.23 defines 'isinf(double)' with a return type of 'int' in
+ // all C++ dialects. The test should tolerate this when libc++ can't work
+ // around it.
// See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439
static_assert((std::is_same<DoubleRetType, bool>::value
|| std::is_same<DoubleRetType, int>::value), "");
More information about the cfe-commits
mailing list