aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-06-25 14:18:36 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-06-25 14:18:36 +0100
commite88d863cbde6ee90709d291670a843346f84d3b6 (patch)
treeca3250791e2d84089352d0a3ea60b47fbcef317e
parent247b63e33d21cb5971ae93c8232a50c678480eeb (diff)
downloadgcc-e88d863cbde6ee90709d291670a843346f84d3b6.zip
gcc-e88d863cbde6ee90709d291670a843346f84d3b6.tar.gz
gcc-e88d863cbde6ee90709d291670a843346f84d3b6.tar.bz2
Fix non-portable use of std::abs(double) in constexpr function
Although libstdc++ adds 'constexpr' to its std::abs(floating-point) overloads (as a non-conforming extension), those overloads are not used if the target libc provides them, which is the case on Solaris. The fix is to avoid std::abs and simply apply the negation when needed. * include/std/numeric (midpoint(T, T)): Avoid std::abs in constexpr function. From-SVN: r272653
-rw-r--r--libstdc++-v3/ChangeLog5
-rw-r--r--libstdc++-v3/include/std/numeric9
2 files changed, 10 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index d739255..7222810 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-25 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/std/numeric (midpoint(T, T)): Avoid std::abs in constexpr
+ function.
+
2019-06-25 Jakub Jelinek <jakub@redhat.com>
* include/pstl/pstl_config.h (_PSTL_PRAGMA_SIMD_SCAN,
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index af68446..2f94621 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -162,7 +162,6 @@ _GLIBCXX_END_NAMESPACE_VERSION
#if __cplusplus > 201703L
#include <limits>
-#include <bits/std_abs.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -196,11 +195,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
constexpr _Tp __lo = numeric_limits<_Tp>::min() * 2;
constexpr _Tp __hi = numeric_limits<_Tp>::max() / 2;
- if (std::abs(__a) <= __hi && std::abs(__b) <= __hi) [[likely]]
+ const _Tp __abs_a = __a < 0 ? -__a : __a;
+ const _Tp __abs_b = __b < 0 ? -__b : __b;
+ if (__abs_a <= __hi && __abs_b <= __hi) [[likely]]
return (__a + __b) / 2; // always correctly rounded
- if (std::abs(__a) < __lo) // not safe to halve __a
+ if (__abs_a < __lo) // not safe to halve __a
return __a + __b/2;
- if (std::abs(__b) < __lo) // not safe to halve __b
+ if (__abs_b < __lo) // not safe to halve __b
return __a/2 + __b;
return __a/2 + __b/2; // otherwise correctly rounded
}