public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/95545] New: thread:: conflicts with std::thread
@ 2020-06-04 21:32 dje at gcc dot gnu.org
2020-06-04 21:32 ` [Bug libstdc++/95545] " dje at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: dje at gcc dot gnu.org @ 2020-06-04 21:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
Bug ID: 95545
Summary: thread:: conflicts with std::thread
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: dje at gcc dot gnu.org
Target Milestone: ---
AIX, MSVC, and possibly other systems, implemented their own definition of
thread different from Posix threads.
libstdc++ <thread> header eventually includes <gthr-posix.h>, which includes
the system <pthread.h> header, which, on AIX, eventually includes
<sys/thread.h>
The AIX header nicely does
#ifdef __cplusplus
extern "C" {
#endif
struct thread {
...
}
which creates an ambiguity when a user references thread:: without std::thread.
LLVM C++ has a pattern that helps to avoid the conflict because of a similar
problem for MSVC:
namespace llvm {
typedef std::thread thread;
}
llvm/include/llvm/Support/thread.h
Would libstdc++ consider a similar solution?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
@ 2020-06-04 21:32 ` dje at gcc dot gnu.org
2020-06-04 21:35 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: dje at gcc dot gnu.org @ 2020-06-04 21:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
David Edelsohn <dje at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-06-04
--- Comment #1 from David Edelsohn <dje at gcc dot gnu.org> ---
Confirmed for AIX and MSVC.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
2020-06-04 21:32 ` [Bug libstdc++/95545] " dje at gcc dot gnu.org
@ 2020-06-04 21:35 ` redi at gcc dot gnu.org
2020-06-04 21:40 ` dje at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-04 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #0)
> which creates an ambiguity when a user references thread:: without
> std::thread.
Could you show an example of code that's ambiguous?
> Would libstdc++ consider a similar solution?
Could you clarify what the solution involves?
Basically I don't understand the problem being described, so I don't see how to
solve it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
2020-06-04 21:32 ` [Bug libstdc++/95545] " dje at gcc dot gnu.org
2020-06-04 21:35 ` redi at gcc dot gnu.org
@ 2020-06-04 21:40 ` dje at gcc dot gnu.org
2020-06-04 21:44 ` dje at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: dje at gcc dot gnu.org @ 2020-06-04 21:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
--- Comment #3 from David Edelsohn <dje at gcc dot gnu.org> ---
#include <stdio.h>
#include <thread>
using namespace std;
int main(void)
{
int maxThreads = thread::hardware_concurrency();
printf("maxThreads: %d\n", maxThreads);
return(0);
}
$ g++ -pthread /tmp/nameclash.cpp -o /tmp/nc
/tmp/nameclash.cpp: In function 'int main()':
/tmp/nameclash.cpp:7:19: error: reference to 'thread' is ambiguous
int maxThreads = thread::hardware_concurrency();
^~~~~~
In file included from /tmp/nameclash.cpp:2:
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/thread:62:9: note:
candidates are: 'class std::thread'
class thread
^~~~~~
In file included from /usr/include/sys/ptrace.h:28,
from /usr/include/sys/proc.h:44,
from /usr/include/sys/pri.h:43,
from /usr/include/sys/sched.h:38,
from /usr/include/sched.h:51,
from /usr/include/pthread.h:63,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/powerpc-ibm-aix7.2.0.0/pthread/bits/gthr-posix.h:35,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/powerpc-ibm-aix7.2.0.0/pthread/bits/gthr-default.h:30,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/powerpc-ibm-aix7.2.0.0/pthread/bits/gthr.h:148,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/ext/atomicity.h:35,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/memory:73,
from
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/thread:39,
from /tmp/nameclash.cpp:2:
/usr/include/sys/thread.h:106:8: note: 'struct thread'
struct thread {
^~~~~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
` (2 preceding siblings ...)
2020-06-04 21:40 ` dje at gcc dot gnu.org
@ 2020-06-04 21:44 ` dje at gcc dot gnu.org
2020-06-04 21:52 ` redi at gcc dot gnu.org
2020-06-04 21:54 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: dje at gcc dot gnu.org @ 2020-06-04 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
David Edelsohn <dje at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |WONTFIX
Status|NEW |RESOLVED
--- Comment #4 from David Edelsohn <dje at gcc dot gnu.org> ---
Impossible.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
` (3 preceding siblings ...)
2020-06-04 21:44 ` dje at gcc dot gnu.org
@ 2020-06-04 21:52 ` redi at gcc dot gnu.org
2020-06-04 21:54 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-04 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem is that 'using namespace std;' introduces an ambiguity. That is in
the user's code, there's nothing we can do in libstdc++ to avoid it.
We could add a different name for std::thread eg.
namespace __gnu_cxx { using thread = std::thread; }
and then users could be careful to always refer to __gnu_cxx::thread instead of
just thread.
But firstly, that is just a different portability problem, because that won't
work with the MSVC library or with libc++. And secondly, if you're going to be
careful and always refer to it with a qualified name, just use std::thread.
Referring to std::thread is portable and always works.
Alternatively, put the 'using namespace std;' at function scope, so that inside
the main() function name lookup finds std::thread, and never looks in the
global scope to find ::thread.
We could do:
namespace std { using __fred = thread; }
which would allow the code to have 'using namespace std;' at global scope, and
refer to __fred::hardware_concurrency() unqualified, but that's still not
portable.
The user code causes the problem, and the user code needs to fix it. There's no
libstdc++ bug and nothing libstdc++ can do that doesn't just shift the problem
somewhere else.
There are similar problems for any name in std:: which also exists at global
scope on some platforms, e.g. std::bind conflicts with POSIX bind(3).
It's well known that 'using namespace std;' causes problems like this. Even if
it works today, it might not work in future because new versions of the C++
standard will add new names to namespace std, so 'using namespace std;' is
basically asking for an unbounded set of names to be dropped into the global
namespace, with potential collisions.
Either refer to 'std::thread' explicitly or introduce the name 'thread' into a
more narrow scope than the one that already has the AIX 'thread'.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/95545] thread:: conflicts with std::thread
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
` (4 preceding siblings ...)
2020-06-04 21:52 ` redi at gcc dot gnu.org
@ 2020-06-04 21:54 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-04 21:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
See
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-using
in the C++ Core Guidelines.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-06-04 21:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 21:32 [Bug libstdc++/95545] New: thread:: conflicts with std::thread dje at gcc dot gnu.org
2020-06-04 21:32 ` [Bug libstdc++/95545] " dje at gcc dot gnu.org
2020-06-04 21:35 ` redi at gcc dot gnu.org
2020-06-04 21:40 ` dje at gcc dot gnu.org
2020-06-04 21:44 ` dje at gcc dot gnu.org
2020-06-04 21:52 ` redi at gcc dot gnu.org
2020-06-04 21:54 ` 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).