]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Format %r, %x and %X using locale's time_put facet [PR120648]
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 13 Jun 2025 11:28:30 +0000 (13:28 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 13 Jun 2025 15:20:30 +0000 (17:20 +0200)
commit33e3139f5df09a13b8b13844d8e21ef3bb4d618e
tree5d2296482d3a64c6efd58322ee44a6b1af148bff
parent5e8168a659ecc63804984d20365b4df401d9675b
libstdc++: Format %r, %x and %X using locale's time_put facet [PR120648]

Similarly to issue reported for %c in PR117214, the format string for locale
specific time (%r, %X) and date (%x) representations may contain specifiers
not accepted by chrono-spec, leading to exception being thrown. This
happened for following conversion specifier and locale combinations:
 * %r, %X for aa_DJ.UTF-8, ar_SA.UTF-8
 * %x for ca_AD.UTF-8, my_MM.UTF-8

This fix follows approach from r15-8490-gc24a1d5, and uses time_put to emit
localized date format. The existing _M_c is reworked to handle all locale
dependent conversion specifies, by accepting them as argument. It is also
renamed to _M_c_r_x_X.

PR libstdc++/120648

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_format_to):
Handle %c, %r, %x and %X by passing them to _M_c_r_x_X.
(__formatter_chrono::_M_c_r_x_X): Reworked from _M_c.
(__formatter_chrono::_M_c): Renamed into above.
(__formatter_chrono::_M_r, __formatter_chrono::_M_x)
(__formatter_chrono::_M_X): Removed.
* testsuite/std/time/format/pr117214.cc: New tests for %r, %x,
%X with date, time and durations.
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/format/pr117214.cc