https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126364
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <[email protected]>: https://gcc.gnu.org/g:5a457c7ba71bebfa1c07a4d4bba8a13b03bba2f4 commit r17-2851-g5a457c7ba71bebfa1c07a4d4bba8a13b03bba2f4 Author: Jonathan Wakely <[email protected]> Date: Wed Jul 29 19:04:37 2026 +0100 libstdc++: Make chrono::parse accept out-of-range values that aren't needed [PR126364] When parsing a time with %R or %T we should ignore out of range hours and minutes if the type being parsed doesn't need them, e.g. when parsing a chrono::year_month_day from "2026-07-29 99:99:99" we do not set failbit, and should continue parsing after the invalid hours and minutes. Because we were short circuiting as soon as we saw "99" (in either field) we didn't parse to the end of the %R or %T field, and then could set failbit if there were any subsequent characters or flags to parse. The fix is to only short-circuit when setting failbit, and continue parsing otherwise. With this change, we no longer hit the 'break' when __read_unsigned(2) returns -1 (e.g. because the input was non-numeric) unless we're parsing a type that needs the %R or %T value. But that's OK, because __read_unsigned sets failbit when it returns -1 and so the next __read_chr or __read_unsigned will fail without extracting more characters, and we'll break there instead. So there's no change in observable behaviour for non-numeric inputs, only for out-of-range numeric inputs. libstdc++-v3/ChangeLog: PR libstdc++/126364 * include/bits/chrono_io.h (_Parser::operator()) <R>: Only break early when setting failbit. * testsuite/std/time/parse/126364.cc: New test. Reviewed-by: Tomasz KamiÅski <[email protected]>
