diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-03-07 13:15:41 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-03-07 22:52:49 +0000 |
commit | 5f9d7a5b6cf64639274e63051caf70fbc8418ea2 (patch) | |
tree | 97b2ed6bc5d5d5aa40943fe82a06aef91ddda9a4 /libstdc++-v3/include/bits/regex.h | |
parent | 9ccd03dee4c35a24c6699a58a7251a5277a91cf5 (diff) | |
download | gcc-5f9d7a5b6cf64639274e63051caf70fbc8418ea2.zip gcc-5f9d7a5b6cf64639274e63051caf70fbc8418ea2.tar.gz gcc-5f9d7a5b6cf64639274e63051caf70fbc8418ea2.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3/include/bits/regex.h')
0 files changed, 0 insertions, 0 deletions