]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Simplify chrono::__units_suffix using std::format
authorJonathan Wakely <jwakely@redhat.com>
Tue, 15 Aug 2023 15:35:22 +0000 (16:35 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 17 Aug 2023 19:24:17 +0000 (20:24 +0100)
commitc992acdc6774ef3d566fab5f324d254bed1b9d4b
tree8efe75b5a295fd8bc1b1c4b67baf6b49fe1c9898
parent023a62b77f999b002d4c56a94475684a4d209788
libstdc++: Simplify chrono::__units_suffix using std::format

For std::chrono formatting we can simplify __units_suffix by using
std::format_to to generate the "[n/m]s" suffix with the correct
character type and write directly to the output iterator, so it doesn't
need to be widened using ctype. We can't remove the use of ctype::widen
for formatting a time zone abbreviation as a wide string, because that
can contain arbitrary characters that can't be widened by
__to_wstring_numeric.

This also fixes a bug in the chrono formatter for %Z which created a
dangling wstring_view.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__units_suffix_misc): Remove.
(__units_suffix): Return a known suffix as string view, do not
write unknown suffixes to a buffer.
(__fmt_units_suffix): New function that formats the suffix using
std::format_to.
(operator<<, __chrono_formatter::_M_q): Use __fmt_units_suffix.
(__chrono_formatter::_M_Z): Correct lifetime of wstring.
libstdc++-v3/include/bits/chrono_io.h