aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorMatthias Kretz <m.kretz@gsi.de>2022-01-18 17:04:06 +0100
committerMatthias Kretz <m.kretz@gsi.de>2022-01-19 13:45:58 +0100
commit39f581028c76ebfc94a5c2714f43c9e56089a9b0 (patch)
tree3a06c8127a051a0b74024a05dc4234f9d95ae3d3 /libstdc++-v3
parent2cef99175af1ad95283d4b35bced73c3a510f6d6 (diff)
downloadgcc-39f581028c76ebfc94a5c2714f43c9e56089a9b0.zip
gcc-39f581028c76ebfc94a5c2714f43c9e56089a9b0.tar.gz
gcc-39f581028c76ebfc94a5c2714f43c9e56089a9b0.tar.bz2
libstdc++: Fix for non-constexpr math_errhandling
Use SFINAE magic to support: "It is unspecified whether math_errhandling is a macro or an identifier with external linkage." [C Standard] Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__floating_point_flags): Do not rely on math_errhandling to expand to a constant expression.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/experimental/bits/simd.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index c991e3f..82e9841 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -283,20 +283,34 @@ constexpr inline bool __have_power_vmx = __have_power_vsx;
namespace __detail
{
- constexpr bool __handle_fpexcept =
#ifdef math_errhandling
- math_errhandling & MATH_ERREXCEPT;
-#elif defined __FAST_MATH__
- false;
+ // Determines _S_handle_fpexcept from math_errhandling if it is defined and expands to a constant
+ // expression. math_errhandling may expand to an extern symbol, in which case a constexpr value
+ // must be guessed.
+ template <int = math_errhandling>
+ constexpr bool __handle_fpexcept_impl(int)
+ { return math_errhandling & MATH_ERREXCEPT; }
+#endif
+
+ // Fallback if math_errhandling doesn't work: with fast-math assume floating-point exceptions are
+ // ignored, otherwise implement correct exception behavior.
+ constexpr bool __handle_fpexcept_impl(float)
+ {
+#if defined __FAST_MATH__
+ return false;
#else
- true;
+ return true;
#endif
+ }
+
+ /// True if math functions must raise floating-point exceptions as specified by C17.
+ static constexpr bool _S_handle_fpexcept = __handle_fpexcept_impl(0);
constexpr std::uint_least64_t
__floating_point_flags()
{
std::uint_least64_t __flags = 0;
- if constexpr (__handle_fpexcept)
+ if constexpr (_S_handle_fpexcept)
__flags |= 1;
#ifdef __FAST_MATH__
__flags |= 1 << 1;