GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

chrono::parse accepts out-of-range values not needed by target type

`chrono::parse` now correctly handles out-of-range time values when they are not required by the target type, preventing unnecessary parse failures.

The chrono::parse function now correctly handles out-of-range hour and minute values when parsing time strings, such as those using %R or %T. Previously, it would prematurely fail the parse operation even if the target type, like chrono::year_month_day, did not strictly require those specific hour/minute values. The fix ensures parsing continues, and failbit is only set if subsequent parsing fails or if the value is truly needed and out of range.

In Details

The _Parser::operator() in chrono_io.h has been modified to prevent premature short-circuiting when parsing time components for %R or %T. The failbit is now only set when parsing truly fails (e.g., __read_unsigned returns -1 and the value is required), rather than immediately upon encountering an out-of-range but unneeded value. This aligns behavior with cases where the target type does not depend on hour or minute fields.

For Context
chrono::parse
A function in the C++ standard library's <chrono> header used for parsing time strings into time-related objects.
%R
A format specifier for strftime and strptime that represents the time in 24-hour notation (HH:MM).
%T
A format specifier for strftime and strptime that represents the time as HH:MM:SS.
failbit
A flag in C++ stream states that indicates a formatting or extraction error occurred during input operations.
chrono::year_month_day
A C++20 chrono type representing a year, month, and day.
Filed Under: libstdc++chronoparsingbugfix