]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix build for targets without FP std::from_chars [PR114633]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 8 Apr 2024 16:37:32 +0000 (17:37 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 9 Apr 2024 23:21:41 +0000 (00:21 +0100)
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

index b9eb3d2be5312ca46fc21d97a1620d9e71667053..3b34992b42a02ab34cfa2d9507fdae779565173c 100644 (file)
@@ -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)