]> 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>
Tue, 1 Jul 2025 15:38:33 +0000 (17:38 +0200)
commitfc36a902340a3a6dcfbe84c7d62c96268d413dc2
treecaa99c025031eca766d38fad4681ed015f15fed0
parentc3a639d1e2f31532b9210a7e31c87f9dda9e9351
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.

(cherry picked from commit 33e3139f5df09a13b8b13844d8e21ef3bb4d618e)
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/format/pr117214.cc