]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fixed localized empty-spec formatting for months/weekdays [PR121154]
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 18 Jul 2025 09:30:22 +0000 (11:30 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 18 Jul 2025 13:29:01 +0000 (15:29 +0200)
commitd31c76cb844154ccd638abc642b9bbb5fea519d4
treed59eeeb7146f4acb28ee4e123d3aa2fc42c5ddef
parent6f275d36288814b09c3d30b51903d29e1ada377c
libstdc++: Fixed localized empty-spec formatting for months/weekdays [PR121154]

Previously for localized output, if _M_debug option was set, the _M_check_ok
completed succesfully and _M_locale_fmt was called for months/weekdays that
are !ok().

This patch lifts debug checks from each conversion function into _M_check_ok,
that in case of !ok() values return a string_view containing the kind of
calendar data, to be included after "is not a valid" string. The localized
output (_M_locale_fmt) is not used if string is non-empty. Emitting of this
message is now handled in _M_format_to, further reducing each specifier
function.

To handle weekday (%a,%A) and month (%b,%B), _M_check_ok now accepts a
mutable reference to conversion specifier, and updates it to corresponding
numeric value (%w, %m). Extra care needs to be taken to handle a month(0)
that needs to be printed as single digit in debug format.

Finally, the _M_time_point is replaced with _M_needs_ok_check member, that
indicates if input contains any user-suplied values that are checked for
being ok() and these values are referenced in chrono-specs.

PR libstdc++/121154

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (_ChronoSpec::_M_time_point): Remove.
(_ChronoSpec::_M_needs_ok_check): Define
(__formatter_chrono::_M_parse): Set _M_needs_ok_check.
(__formatter_chrono::_M_check_ok): Check values also for debug mode,
and return __string_view.
(__formatter_chrono::_M_format_to): Handle results of _M_check_ok.
(__formatter_chrono::_M_wi, __formatter_chrono::_M_a_A)
(__formatter_chrono::_M_b_B, __formatter_chrono::_M_C_y_Y)
(__formatter_chrono::_M_d_e, __formatter_chrono::_M_F):
Removed handling of _M_debug.
(__formatter_chrono::__M_m): Print zero unpadded in _M_debug mode.
(__formatter_duration::_S_spec_for): Remove _M_time_point refernce.
(__formatter_duration::_M_parse): Override _M_needs_ok_check.
* testsuite/std/time/month/io.cc: Test for localized !ok() values.
* testsuite/std/time/weekday/io.cc: Test for localized !ok() values.
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/month/io.cc
libstdc++-v3/testsuite/std/time/weekday/io.cc