https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114244
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:5f9d7a5b6cf64639274e63051caf70fbc8418ea2 commit r14-9376-g5f9d7a5b6cf64639274e63051caf70fbc8418ea2 Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Mar 7 13:15:41 2024 +0000 libstdc++: Fix parsing of fractional seconds [PR114244] When converting a chrono::duration<long double> to a result type with an integer representation we should use chrono::round<_Duration> so that we don't truncate towards zero. Rounding ensures that e.g. 0.001999s becomes 2ms not 1ms. We can also remove some redundant uses of chrono::duration_cast to convert from seconds to _Duration, because the _Parser class template requires _Duration type to be able to represent seconds without loss of precision. This also fixes a bug where no fractional part would be parsed for chrono::duration<long double> because its period is ratio<1>. We should also consider treat_as_floating_point<rep> when deciding whether to skip reading a fractional part. libstdc++-v3/ChangeLog: PR libstdc++/114244 * include/bits/chrono_io.h (_Parser::operator()): Remove redundant uses of duration_cast. Use chrono::round to convert long double value to durations with integer representations. Check represenation type when deciding whether to skip parsing fractional seconds. * testsuite/20_util/duration/114244.cc: New test. * testsuite/20_util/duration/io.cc: Check that a floating-point duration with ratio<1> precision can be parsed.