]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix %S format of duration with floating-point rep
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Dec 2023 15:26:42 +0000 (15:26 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 15 Dec 2023 11:33:17 +0000 (11:33 +0000)
I got the order of arguments to std::format_to wrong. It was in a
discarded statement, for a case which wasn't being tested.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_S): Fix order
of arguments to std::format_to.
* testsuite/20_util/duration/io.cc: Test subsecond duration with
floating-point rep.

(cherry picked from commit 2ef5200a6fb7311074904a1b4bf7ce750618a068)

libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/20_util/duration/io.cc

index c94adff3cec54c858eb23ddabba945906f2b95fe..99cacc97fae5e8d71f512f91ef396553e7baadc4 100644 (file)
@@ -1159,7 +1159,7 @@ namespace __format
              using rep = typename decltype(__ss)::rep;
              if constexpr (is_floating_point_v<rep>)
                {
-                 __out = std::format_to(__loc, std::move(__out),
+                 __out = std::format_to(std::move(__out), __loc,
                                         _GLIBCXX_WIDEN("{:.{}Lg}"),
                                         __ss.count(),
                                         __hms.fractional_width);
index 034167c61925ff428259a558ff702fea9f88da6f..5f0f25eac69d9049a83143385434c674db733cb1 100644 (file)
@@ -96,6 +96,10 @@ test_format()
                    "required by the chrono-specs") != s.npos);
     }
   }
+
+  std::chrono::duration<float, std::milli> d{0.5};
+  s = std::format("{}", d);
+  VERIFY( s == "0.5ms" );
 }
 
 int main()