public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113500] Using std::format with float or double based std::chrono::time_point causes error: no match for 'operator<<' Date: Tue, 30 Jan 2024 14:55:01 +0000 [thread overview] Message-ID: <bug-113500-4-afCmuOt6ki@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-113500-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113500 --- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-13 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:a5aca83ca9c7fac895d10eb7b3e14b1927ec1eac commit r13-8263-ga5aca83ca9c7fac895d10eb7b3e14b1927ec1eac Author: Jonathan Wakely <jwakely@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. (cherry picked from commit 7431fcea6b72beb54abb1932c254ac0e76bd0bde)
next prev parent reply other threads:[~2024-01-30 14:55 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-19 7:11 [Bug libstdc++/113500] New: " Hirthammer@allterra-dno.de 2024-01-19 7:40 ` [Bug libstdc++/113500] " redi at gcc dot gnu.org 2024-01-19 7:45 ` redi at gcc dot gnu.org 2024-01-19 8:14 ` Hirthammer@allterra-dno.de 2024-01-19 11:49 ` redi at gcc dot gnu.org 2024-01-19 13:09 ` Hirthammer@allterra-dno.de 2024-01-19 13:39 ` redi at gcc dot gnu.org 2024-01-19 13:44 ` redi at gcc dot gnu.org 2024-01-19 21:26 ` redi at gcc dot gnu.org 2024-01-21 22:25 ` cvs-commit at gcc dot gnu.org 2024-01-21 22:27 ` redi at gcc dot gnu.org 2024-01-22 8:37 ` Hirthammer@allterra-dno.de 2024-01-30 14:55 ` cvs-commit at gcc dot gnu.org [this message] 2024-01-30 15:18 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-113500-4-afCmuOt6ki@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).