public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/109921] c++17/floating_from_chars.cc: compile error: ‘from_chars_strtod’ was not declared in this scope
Date: Wed, 24 May 2023 13:01:14 +0000	[thread overview]
Message-ID: <bug-109921-4-CLrOZ4cthQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109921-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109921

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The proposed change would result in ABI changes for some targets.

I think the correct fix is something more like this:

--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -64,7 +64,7 @@
 // strtold for __ieee128
 extern "C" __ieee128 __strtoieee128(const char*, char**);
 #elif __FLT128_MANT_DIG__ == 113 && __LDBL_MANT_DIG__ != 113 \
-      && defined(__GLIBC_PREREQ)
+      && defined(__GLIBC_PREREQ) && defined(USE_STRTOD_FOR_FROM_CHARS)
 #define USE_STRTOF128_FOR_FROM_CHARS 1
 extern "C" _Float128 __strtof128(const char*, char**)
   __asm ("strtof128")
@@ -77,10 +77,6 @@ extern "C" _Float128 __strtof128(const char*, char**)
 #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 \
     && __SIZE_WIDTH__ >= 32
 # define USE_LIB_FAST_FLOAT 1
-# if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__
-// No need to use strtold.
-#  undef USE_STRTOD_FOR_FROM_CHARS
-# endif
 #endif

 #if USE_LIB_FAST_FLOAT
@@ -1261,7 +1257,7 @@ from_chars_result
 from_chars(const char* first, const char* last, long double& value,
           chars_format fmt) noexcept
 {
-#if ! USE_STRTOD_FOR_FROM_CHARS
+#if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ || !defined
USE_STRTOD_FOR_FROM_CHARS
   // Either long double is the same as double, or we can't use strtold.
   // In the latter case, this might give an incorrect result (e.g. values
   // out of range of double give an error, even if they fit in long double).
@@ -1329,13 +1325,23 @@ _ZSt10from_charsPKcS0_RDF128_St12chars_format(const
char* first,
                                              __ieee128& value,
                                              chars_format fmt) noexcept
 __attribute__((alias ("_ZSt10from_charsPKcS0_Ru9__ieee128St12chars_format")));
-#elif defined(USE_STRTOF128_FOR_FROM_CHARS)
+#else
 from_chars_result
 from_chars(const char* first, const char* last, _Float128& value,
           chars_format fmt) noexcept
 {
+#ifdef USE_STRTOF128_FOR_FROM_CHARS
   // fast_float doesn't support IEEE binary128 format, but we can use strtold.
   return from_chars_strtod(first, last, value, fmt);
+#else
+  // Read a long double. This might give an incorrect result (e.g. values
+  // out of range of long double give an error, even if they fit in
_Float128).
+  long double ldbl_val;
+  auto res = std::from_chars(first, last, ldbl_val, fmt);
+  if (rec.ec == errc{})
+    value = ldbl_val;
+  return res;
+#endif
 }
 #endif


We should not use strtof128 unless we can use strtod.

We should not #undef USE_STRTOD_FOR_FROM_CHARS on line 82 just because we don't
need it for long double, as we might still need it for _Float128.

  parent reply	other threads:[~2023-05-24 13:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-21 10:02 [Bug libstdc++/109921] New: " br015 at umbiko dot net
2023-05-24 11:16 ` [Bug libstdc++/109921] " redi at gcc dot gnu.org
2023-05-24 13:01 ` redi at gcc dot gnu.org [this message]
2023-05-25  8:31 ` br015 at umbiko dot net
2023-05-31 12:21 ` cvs-commit at gcc dot gnu.org
2023-05-31 12:24 ` redi at gcc dot gnu.org
2023-05-31 19:57 ` cvs-commit at gcc dot gnu.org
2023-07-19 19:53 ` redi at gcc dot gnu.org
2023-07-19 22:43 ` [Bug libstdc++/109921] [13 Regression] " cvs-commit at gcc dot gnu.org
2023-07-19 23:31 ` cvs-commit at gcc dot gnu.org
2023-07-19 23:33 ` redi at gcc dot gnu.org
2023-07-20 11:57 ` redi at gcc dot gnu.org
2023-07-21 13:04 ` redi at gcc dot gnu.org
2023-07-22  6:05 ` br015 at umbiko dot net
2023-07-22  9:01 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109921-4-CLrOZ4cthQ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).