public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix build for targets without FP std::from_chars [PR114633]
Date: Wed, 10 Apr 2024 00:22:00 +0100	[thread overview]
Message-ID: <20240409232229.252976-1-jwakely@redhat.com> (raw)

Tested x86_64-linux. Richi confirmed this fixes rx-elf bootstrap.

Pushed to trunk.

-- >8 --

If the faster std::from_chars is not supported for floating-point types
then just extract the value from the stream using operator>>.

This fixes a build error for targets where __cpp_lib_to_chars is not
defined.

libstdc++-v3/ChangeLog:

	PR libstdc++/114633
	* include/bits/chrono_io.h (_Parser::operator()) <'S'>: Use
	stream extraction if std::from_chars is not available.
---
 libstdc++-v3/include/bits/chrono_io.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index b9eb3d2be53..3b34992b42a 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -3685,6 +3685,7 @@ namespace __detail
 		      if (!__is_failed(__err)) [[likely]]
 			{
 			  long double __val{};
+#if __cpp_lib_to_chars
 			  string __str = std::move(__buf).str();
 			  auto __first = __str.data();
 			  auto __last = __first + __str.size();
@@ -3694,6 +3695,9 @@ namespace __detail
 			  if ((bool)ec || ptr != __last) [[unlikely]]
 			    __err |= ios_base::failbit;
 			  else
+#else
+			  if (__buf >> __val)
+#endif
 			    {
 			      duration<long double> __fs(__val);
 			      if constexpr (__is_floating)
-- 
2.44.0


                 reply	other threads:[~2024-04-09 23:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240409232229.252976-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@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).