public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/115099] New: compilation error: format thread::id
@ 2024-05-15 4:16 faithandbrave at gmail dot com
2024-05-16 11:58 ` [Bug libstdc++/115099] " de34 at live dot cn
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: faithandbrave at gmail dot com @ 2024-05-15 4:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115099
Bug ID: 115099
Summary: compilation error: format thread::id
Product: gcc
Version: 14.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: faithandbrave at gmail dot com
Target Milestone: ---
#include <iostream>
#include <format>
#include <thread>
int main()
{
std::cout << __cpp_lib_formatters << std::endl;
std::cout << std::format("{}", std::this_thread::get_id()) << std::endl;
std::cout << std::format("{: >30}", std::this_thread::get_id()) <<
std::endl;
}
outputs:
In file included from prog.cc:3:
/opt/wandbox/gcc-head/include/c++/15.0.0/thread: In instantiation of 'typename
std::basic_format_context<_Out, _CharT>::iterator
std::formatter<std::thread::id, _CharT>::format(std::thread::id,
std::basic_format_context<_Out, _CharT>&) const [with _Out =
std::__format::_Sink_iter<char>; _CharT = char; typename
std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<char>, char>::iterator]':
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3247:40: required from
'static void
std::basic_format_arg<_Context>::handle::_S_format(std::basic_format_parse_context<typename
_Context::char_type>&, _Context&, const void*) [with _Tq = const
std::thread::id; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>; typename
_Context::char_type = char]'
3247 | __format_ctx.advance_to(__f.format(__val, __format_ctx));
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3255:11: required from
'std::basic_format_arg<_Context>::handle::handle(_Tp&) [with _Tp =
std::thread::id; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>]'
3255 | auto __func = _S_format<__maybe_const_t<_Tp>>;
| ^~~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3486:13: required from
'std::basic_format_arg<_Context>::basic_format_arg(_Tp&) [with _Tp =
std::thread::id; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>]'
3486 | _M_set(static_cast<_Td>(__v));
| ^~~~~~~~~~~~~~~~~~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3743:31: required from
'static std::__format::_Arg_store<_Context, _Args>::_Element_t
std::__format::_Arg_store<_Context, _Args>::_S_make_elt(_Tp&) [with _Tp =
std::thread::id; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>; _Args =
{std::basic_format_arg<std::basic_format_context<std::__format::_Sink_iter<char>,
char> >::handle}; _Element_t =
std::__format::_Arg_store<std::basic_format_context<std::__format::_Sink_iter<char>,
char>,
std::basic_format_arg<std::basic_format_context<std::__format::_Sink_iter<char>,
char> >::handle>::_Element_t]'
3743 | basic_format_arg<_Context> __arg(__v);
| ^~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3754:23: required from
'std::__format::_Arg_store<_Context, _Args>::_Arg_store(_Tp& ...) [with _Tp =
{std::thread::id}; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>; _Args =
{std::basic_format_arg<std::basic_format_context<std::__format::_Sink_iter<char>,
char> >::handle}]'
3754 | : _M_args{_S_make_elt(__a)...}
| ~~~~~~~~~~~^~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:3804:14: required from 'auto
std::make_format_args(_Args& ...) [with _Context =
basic_format_context<__format::_Sink_iter<char>, char>; _Args = {thread::id}]'
3804 | return _Store(__fmt_args...);
| ^~~~~~~~~~~~~~~~~~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/format:4291:61: required from
'std::string std::format(format_string<_Args ...>, _Args&& ...) [with _Args =
{thread::id}; string = __cxx11::basic_string<char>; format_string<_Args ...> =
basic_format_string<char, thread::id>]'
4291 | { return std::vformat(__fmt.get(),
std::make_format_args(__args...)); }
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
prog.cc:8:29: required from here
8 | std::cout << std::format("{}", std::this_thread::get_id()) <<
std::endl;
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/wandbox/gcc-head/include/c++/15.0.0/thread:334:44: error:
'std::__cxx11::basic_ostringstream<char> __os' has incomplete type
334 | std::basic_ostringstream<_CharT> __os;
| ^~~~
It seems missing include <sstream> at <thread>.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115099] compilation error: format thread::id
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id faithandbrave at gmail dot com
@ 2024-05-16 11:58 ` de34 at live dot cn
2024-05-17 11:50 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: de34 at live dot cn @ 2024-05-16 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115099
Jiang An <de34 at live dot cn> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |de34 at live dot cn
--- Comment #1 from Jiang An <de34 at live dot cn> ---
I guess we shouldn't include <sstream> in <thread>. There should be far more
simple ways to obtain thread::id's text representation.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115099] compilation error: format thread::id
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id 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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-17 11:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115099
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-05-17
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Target Milestone|--- |14.2
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115099] compilation error: format thread::id
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id 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
2024-05-22 11:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-22 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115099
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:1a5e4dd83788ea4c049d354d83ad58a6a3d747e6
commit r15-770-g1a5e4dd83788ea4c049d354d83ad58a6a3d747e6
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115099] compilation error: format thread::id
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id faithandbrave at gmail dot com
` (2 preceding siblings ...)
2024-05-22 9:05 ` cvs-commit at gcc dot gnu.org
@ 2024-05-22 11:44 ` cvs-commit at gcc dot gnu.org
2024-05-22 11:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-22 11:44 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115099] compilation error: format thread::id
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id faithandbrave at gmail dot com
` (3 preceding siblings ...)
2024-05-22 11:44 ` cvs-commit at gcc dot gnu.org
@ 2024-05-22 11:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-22 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115099
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 14.2, thanks for the report.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-22 11:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-15 4:16 [Bug libstdc++/115099] New: compilation error: format thread::id 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
2024-05-22 11:45 ` redi at gcc dot gnu.org
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).