https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113500

--- Comment #9 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:7431fcea6b72beb54abb1932c254ac0e76bd0bde

commit r14-8321-g7431fcea6b72beb54abb1932c254ac0e76bd0bde
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Sun Jan 21 18:16:14 2024 +0000

    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.

Reply via email to