]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++; Do not use strtold for hppa-hpux [PR110653]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Jul 2023 10:45:43 +0000 (11:45 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 24 Jul 2023 19:45:14 +0000 (20:45 +0100)
When I switched std::stold to depend on HAVE_STRTOLD that enabled it for
hppa-hpux which defines HAVE_BROKEN_STRTOLD. Add a check for that macro
so that we don't use strtold, and fall through to the check for double
and long double having the same representation. That should mean we
define a conforming std::stold in terms of std::stod, instead of trying
to use the broken strtold.

Also fix a logic error in the fallback definition of std::stod, which
should not treat zero as a subnormal number.

libstdc++-v3/ChangeLog:

PR libstdc++/110653
* include/bits/basic_string.h [!HAVE_STOF] (stof): Do not
throw an exception for zero result.
[HAVE_BROKEN_STRTOLD] (stold): Do not use strtold.

libstdc++-v3/include/bits/basic_string.h

index e4cb98460254896026dcfef6518719bc724877a0..170a43664c977b15530c4e6fce1f18613af61c0e 100644 (file)
@@ -4148,7 +4148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   stod(const string& __str, size_t* __idx = 0)
   { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
 
-#if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOF
+#if _GLIBCXX_HAVE_STRTOF
   // NB: strtof vs strtod.
   inline float
   stof(const string& __str, size_t* __idx = 0)
@@ -4158,7 +4158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   stof(const string& __str, size_t* __idx = 0)
   {
     double __d = std::stod(__str, __idx);
-    if (__builtin_isfinite(__d))
+    if (__builtin_isfinite(__d) && __d != 0.0)
       {
        double __abs_d = __builtin_fabs(__d);
        if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
@@ -4171,7 +4171,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   }
 #endif
 
-#if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOLD
+#if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
   inline long double
   stold(const string& __str, size_t* __idx = 0)
   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }