diff options
author | Tomasz Kamiński <tkaminsk@redhat.com> | 2025-07-18 11:30:22 +0200 |
---|---|---|
committer | Tomasz Kamiński <tkaminsk@redhat.com> | 2025-07-18 15:29:01 +0200 |
commit | d31c76cb844154ccd638abc642b9bbb5fea519d4 (patch) | |
tree | d59eeeb7146f4acb28ee4e123d3aa2fc42c5ddef /libstdc++-v3/testsuite/std | |
parent | 6f275d36288814b09c3d30b51903d29e1ada377c (diff) | |
download | gcc-d31c76cb844154ccd638abc642b9bbb5fea519d4.zip gcc-d31c76cb844154ccd638abc642b9bbb5fea519d4.tar.gz gcc-d31c76cb844154ccd638abc642b9bbb5fea519d4.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3/testsuite/std')
-rw-r--r-- | libstdc++-v3/testsuite/std/time/month/io.cc | 7 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/std/time/weekday/io.cc | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/std/time/month/io.cc b/libstdc++-v3/testsuite/std/time/month/io.cc index 99ec073..edfa196 100644 --- a/libstdc++-v3/testsuite/std/time/month/io.cc +++ b/libstdc++-v3/testsuite/std/time/month/io.cc @@ -24,6 +24,9 @@ test_ostream() ss.imbue(std::locale(ISO_8859(15,fr_FR))); ss << month(1); VERIFY( ss.str() == "janv." ); + ss.str(""); + ss << month(0) << '|' << month(13); + VERIFY( ss.str() == "0 is not a valid month|13 is not a valid month" ); } void @@ -66,6 +69,10 @@ test_format() VERIFY( s == "Jan" ); s = std::format(loc_fr, "{:L%b}", month(1)); VERIFY( s == "janv." ); + s = std::format(loc_fr, "{:L}", month(0)); + VERIFY( s == "0 is not a valid month" ); + s = std::format(loc_fr, "{:L}", month(13)); + VERIFY( s == "13 is not a valid month" ); std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ"; std::string_view my_specs = "bBhm"; diff --git a/libstdc++-v3/testsuite/std/time/weekday/io.cc b/libstdc++-v3/testsuite/std/time/weekday/io.cc index a56cdae..90a9bcb 100644 --- a/libstdc++-v3/testsuite/std/time/weekday/io.cc +++ b/libstdc++-v3/testsuite/std/time/weekday/io.cc @@ -69,6 +69,8 @@ test_format() VERIFY( s == "Mon" ); s = std::format(loc_fr, "{:L%a}", weekday(1)); VERIFY( s == "lun." ); + s = std::format(loc_fr, "{:L}", weekday(25)); + VERIFY( s == "25 is not a valid weekday" ); std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ"; std::string_view my_specs = "aAuw"; |