]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Fix up some <cmath> templates [PR109883]
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 May 2023 19:21:23 +0000 (21:21 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 17 May 2023 19:21:23 +0000 (21:21 +0200)
commit883f1e25dc7907c9bb37f480b900336a050218f1
tree14939b4ffaed5874697a71fc26d7ecba22b339f6
parent5e1e16d58ec10393eb8aa805e398f30144afbee6
libstdc++: Fix up some <cmath> templates [PR109883]

As can be seen on the following testcase, for
std::{atan2,fmod,pow,copysign,fdim,fmax,fmin,hypot,nextafter,remainder,remquo,fma}
if one operand type is std::float{16,32,64,128}_t or std::bfloat16_t and
another one some integral type or some other floating point type which
promotes to the other operand's type, we can end up with endless recursion.
This is because of a declaration ordering problem in <cmath>, where the
float, double and long double overloads of those functions come before
the templates which use __gnu_cxx::__promote_{2,3}, but the
std::float{16,32,64,128}_t and std::bfloat16_t overloads come later in the
file.  If the result of those promotions is _Float{16,32,64,128} or
__gnu_cxx::__bfloat16_t, say std::pow(_Float64, int) calls
std::pow(_Float64, _Float64) and the latter calls itself.

The following patch fixes that by moving those templates later in the file,
so that the calls from those templates see also the other overloads.

I think other templates in the file like e.g. isgreater etc. shouldn't be
a problem, because those just use __builtin_isgreater etc. in their bodies.

2023-05-17  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/109883
* include/c_global/cmath (atan2, fmod, pow): Move
__gnu_cxx::__promote_2 using templates after _Float{16,32,64,128} and
__gnu_cxx::__bfloat16_t overloads.
(copysign, fdim, fmax, fmin, hypot, nextafter, remainder, remquo):
Likewise.
(fma): Move __gnu_cxx::__promote_3 using template after
_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads.

* testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc: New test.
libstdc++-v3/include/c_global/cmath
libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc [new file with mode: 0644]
This page took 0.066811 seconds and 6 git commands to generate.