Skip to content
Snippets Groups Projects
Commit c992acdc authored by Jonathan Wakely's avatar Jonathan Wakely
Browse files

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.
parent 023a62b7
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment