]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use runtime format for internal format calls in chrono [PR110739]
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 27 Jun 2025 07:50:18 +0000 (09:50 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 27 Jun 2025 14:40:09 +0000 (16:40 +0200)
commite99040403f70cd4741f876bffa64259df8ab2199
tree4ba86aba9a68226de1783357fdaad2e2c7e764b4
parent0337e3c2743ca0c57da8c6b78b725a7d83f0b721
libstdc++: Use runtime format for internal format calls in chrono [PR110739]

This patch adjust all internal std::format call inside of __formatter_chrono,
to use runtime format string and thus avoid compile time checking of validity
of the format string. Majority of cases are covered by calling newly introduced
_S_empty_fs() function that returns __Runtime_format_string containing
_S_empty_spec, instead of passing later directly.

In case of _M_j we use _S_str_d3 function (extracted from _S_str_d2), eliminating
call to std::format outside of unlikely scenario in which day of year is greater
than 1000 (this may happen for year_month_day with month greater than 12). In
consequence, outside of handling subseconds, we no longer delegate to std::format
or construct temporary strings, when formatting chrono types with ok() values.

PR libstdc++/110739

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_S_empty_fs): Define.
(__formatter_chrono::_S_str_d2): Use _S_str_d3 for 3+ digits and
place allways_inline attribute after comment.
(__formatter_chrono::_S_str_d3): Extracted from _S_str_d2.
(__formatter_chrono::_M_H_I, __formatter_chrono::_M_R_X): Replace
_S_empty_spec with _S_empty_fs().
(__formatter_chrono::_M_j): Likewise and use _S_str_d3 in common
case.
(__format::operator-(_ChronoParts, _ChronoParts))
(__format::operator-=(_ChronoParts, _ChronoParts))
(__formatter_chrono::_S_fill_two_digits)
(__formatter_chrono::_S_str_d1): Place always_inline attribute
after comment.
libstdc++-v3/include/bits/chrono_io.h