aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-08 16:15:57 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-03-09 00:21:42 +0000
commit3e8ee03edd018eed43444755f601cdb9d5931654 (patch)
tree0001f51fa1f7d4710dd49d7810c66a1a9577e2ce /libstdc++-v3/include
parentf4a52c184d608325c14338b57f464f7d0bbc7526 (diff)
downloadgcc-3e8ee03edd018eed43444755f601cdb9d5931654.zip
gcc-3e8ee03edd018eed43444755f601cdb9d5931654.tar.gz
gcc-3e8ee03edd018eed43444755f601cdb9d5931654.tar.bz2
libstdc++: Do not require a time-of-day when parsing sys_days [PR114240]
When parsing a std::chrono::sys_days (or a sys_time with an even longer period) we should not require a time-of-day to be present in the input, because we can't represent that in the result type anyway. Rather than trying to decide which specializations should require a time-of-date and which should not, follow the direction of Howard Hinnant's date library, which allows extracting a sys_time of any period from input that only contains a date, defaulting the time-of-day part to 00:00:00. This seems consistent with the intent of the standard, which says it's an error "If the parse fails to decode a valid date" (i.e., it doesn't care about decoding a valid time, only a date). libstdc++-v3/ChangeLog: PR libstdc++/114240 * include/bits/chrono_io.h (_Parser::operator()): Assume hours(0) for a time_point, so that a time is not required to be present. * testsuite/std/time/parse/114240.cc: New test.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/chrono_io.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index eaa36b8..b9eb3d2 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -3157,6 +3157,16 @@ namespace __detail
minutes __tz_offset = __bad_min;
basic_string<_CharT, _Traits> __tz_abbr;
+ if ((_M_need & _ChronoParts::_TimeOfDay)
+ && (_M_need & _ChronoParts::_Year))
+ {
+ // For time_points assume "00:00:00" is implicitly present,
+ // so we don't fail to parse if it's not (PR libstdc++/114240).
+ // We will still fail to parse if there's no year+month+day.
+ __h = hours(0);
+ __parts = _ChronoParts::_TimeOfDay;
+ }
+
// bool __is_neg = false; // TODO: how is this handled for parsing?
_CharT __mod{}; // One of 'E' or 'O' or nul.
@@ -4098,7 +4108,7 @@ namespace __detail
const bool __need_wday = _M_need & _ChronoParts::_Weekday;
// Whether the caller wants _M_sys_days and _M_time.
- // Only true for time_points.
+ // Only true for durations and time_points.
const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
if (__need_wday && __wday != __bad_wday)