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++/115099] compilation error: format thread::id
Date: Wed, 22 May 2024 11:44:29 +0000	[thread overview]
Message-ID: <bug-115099-4-NvANTuL1rn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-115099-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:4896bb3199253dc350f8fb5ff63370310ca27ce2

commit r14-10232-g4896bb3199253dc350f8fb5ff63370310ca27ce2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 17 10:55:32 2024 +0100

    libstdc++: Implement std::formatter<std::thread::id> without <sstream>
[PR115099]

    The std::thread::id formatter uses std::basic_ostringstream without
    including <sstream>, which went unnoticed because the test for it uses
    a stringstream to check the output is correct.

    The fix implemented here is to stop using basic_ostringstream for
    formatting thread::id and just use std::format instead.

    As a drive-by fix, the formatter specialization is constrained to
    require that the thread::id::native_handle_type can be formatted, to
    avoid making the formatter ill-formed if the pthread_t type is not a
    pointer or integer. Since non-void pointers can't be formatted, ensure
    that we convert pointers to const void* for formatting. Make a similar
    change to the existing operator<< overload so that in the unlikely case
    that pthread_t is a typedef for char* we don't treat it as a
    null-terminated string when inserting into a stream.

    libstdc++-v3/ChangeLog:

            PR libstdc++/115099
            * include/bits/std_thread.h: Declare formatter as friend of
            thread::id.
            * include/std/thread (operator<<): Convert non-void pointers to
            void pointers for output.
            (formatter): Add constraint that thread::native_handle_type is a
            pointer or integer.
            (formatter::format): Reimplement without basic_ostringstream.
            * testsuite/30_threads/thread/id/output.cc: Check output
            compiles before <sstream> has been included.

    (cherry picked from commit 1a5e4dd83788ea4c049d354d83ad58a6a3d747e6)

  parent reply	other threads:[~2024-05-22 11:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  4:16 [Bug libstdc++/115099] New: " faithandbrave at gmail dot com
2024-05-16 11:58 ` [Bug libstdc++/115099] " de34 at live dot cn
2024-05-17 11:50 ` redi at gcc dot gnu.org
2024-05-22  9:05 ` cvs-commit at gcc dot gnu.org
2024-05-22 11:44 ` cvs-commit at gcc dot gnu.org [this message]
2024-05-22 11:45 ` 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-115099-4-NvANTuL1rn@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: link
Be 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).