diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index ca84f951400..5c568c70313 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -2880,8 +2880,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr _Float16 nextafter(_Float16 __x, _Float16 __y) { - if (std::__is_constant_evaluated()) - return __builtin_nextafterf16(__x, __y); +#if __cpp_if_consteval >= 202106L + // Can't use if (std::__is_constant_evaluated()) here, as it + // doesn't guarantee optimizing the body away at -O0 and + // nothing defines nextafterf16. + if consteval { return __builtin_nextafterf16(__x, __y); } +#endif #ifdef __INT16_TYPE__ using __float16_int_type = __INT16_TYPE__; #else @@ -3598,8 +3602,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr __gnu_cxx::__bfloat16_t nextafter(__gnu_cxx::__bfloat16_t __x, __gnu_cxx::__bfloat16_t __y) { - if (std::__is_constant_evaluated()) - return __builtin_nextafterf16b(__x, __y); +#if __cpp_if_consteval >= 202106L + // Can't use if (std::__is_constant_evaluated()) here, as it + // doesn't guarantee optimizing the body away at -O0 and + // nothing defines nextafterf16b. + if consteval { return __builtin_nextafterf16b(__x, __y); } +#endif #ifdef __INT16_TYPE__ using __bfloat16_int_type = __INT16_TYPE__; #else diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/117321.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/117321.cc new file mode 100644 index 00000000000..18d108c6a3e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/117321.cc @@ -0,0 +1,5 @@ +// { dg-do run { target c++23 } } +// { dg-require-cmath "" } +// { dg-additional-options "-O0" } + +#include "nextafter_c++23.cc"