]> 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>
Thu, 14 Dec 2023 22:04:42 +0000 (22:04 +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.

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

index bcd76e4ab7b06617d522e9f7771e5f355fba3ef2..c30451651ea310720e0a1b31cb5c6fdb23c85195 100644 (file)
@@ -1137,7 +1137,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 d2b9de73f83adbd9a553fdf88390d70775860dcf..0582c0075a56d2fd85c1b048a3a4c4284b840342 100644 (file)
@@ -95,6 +95,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" );
 }
 
 void