[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 --- Comment #6 from Jonathan Wakely --- See https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-using in the C++ Core Guidelines.
[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 --- Comment #5 from Jonathan Wakely --- 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'.
[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 David Edelsohn changed: What|Removed |Added Resolution|--- |WONTFIX Status|NEW |RESOLVED --- Comment #4 from David Edelsohn --- Impossible.
[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 --- Comment #3 from David Edelsohn --- #include #include 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 { ^~
[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 --- Comment #2 from Jonathan Wakely --- (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.
[Bug libstdc++/95545] thread:: conflicts with std::thread
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95545 David Edelsohn changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed||2020-06-04 --- Comment #1 from David Edelsohn --- Confirmed for AIX and MSVC.