aboutsummaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-01-21 18:16:14 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-01-21 22:15:06 +0000
commit7431fcea6b72beb54abb1932c254ac0e76bd0bde (patch)
tree8225909fd4326ec917fb9c71c95720a7f7d7c507 /libiberty
parentfba15da8fa518bfb8d3e061795bc3ca2dea01d27 (diff)
downloadgcc-7431fcea6b72beb54abb1932c254ac0e76bd0bde.zip
gcc-7431fcea6b72beb54abb1932c254ac0e76bd0bde.tar.gz
gcc-7431fcea6b72beb54abb1932c254ac0e76bd0bde.tar.bz2
libstdc++: Fix std::format for floating-point chrono::time_point [PR113500]
Currently trying to use std::format with certain specializations of std::chrono::time_point is ill-formed, due to one member function of the __formatter_chrono type which tries to write a time_point to an ostream. For sys_time<floating-point> or sys_time with a period greater than days there is no operator<< that can be used. That operator<< is only needed when using an empty chrono-specs in the format string, like "{}", but the ill-formed expression gives an error even if not actually used. This means it's not possible to format some other specializations of chrono::time_point, even when using a non-empty chrono-specs. This fixes it by avoiding using 'os << t' for all chrono::time_point specializations, and instead using std::format("{:L%F %T}", t). So that we continue to reject std::format("{}", sys_time{1.0s}) a check for empty chrono-specs is added to the formatter<sys_time<D>, C> specialization. While testing this I noticed that the output for %S with a floating-point duration was incorrect, as the subseconds part was being appended to the seconds without a decimal point, and without the correct number of leading zeros. libstdc++-v3/ChangeLog: PR libstdc++/113500 * include/bits/chrono_io.h (__formatter_chrono::_M_S): Fix printing of subseconds with floating-point rep. (__formatter_chrono::_M_format_to_ostream): Do not write time_point specializations directly to the ostream. (formatter<chrono::sys_time<D>, C>::parse): Do not allow an empty chrono-spec if the type fails to meet the constraints for writing to an ostream with operator<<. * testsuite/std/time/clock/file/io.cc: Check formatting non-integral times with empty chrono-specs. * testsuite/std/time/clock/gps/io.cc: Likewise. * testsuite/std/time/clock/utc/io.cc: Likewise. * testsuite/std/time/hh_mm_ss/io.cc: Likewise.
Diffstat (limited to 'libiberty')
0 files changed, 0 insertions, 0 deletions