This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/49668] New: [C++0x] std::thread does not forward its args as rvalues
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 7 Jul 2011 08:31:00 +0000
- Subject: [Bug libstdc++/49668] New: [C++0x] std::thread does not forward its args as rvalues
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49668
Summary: [C++0x] std::thread does not forward its args as
rvalues
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: redi@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
Created attachment 24702
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24702
do not use std::bind to implement std::thread
#include <thread>
struct moveable
{
moveable() = default;
moveable(moveable&&) = default;
};
void f(moveable) { }
int main()
{
std::thread t(f, moveable());
t.join();
}
The problem is that std::thread uses std::bind internally and the call wrapper
returned by std::bind forwards the bound args as lvalues (this is necessary
because the call wrapper could be invoked multiple times, so the arguments
cannot be moved from)
std::thread doesn't need most of the functionality of std::bind anyway, and
using it actually makes this ill-formed because std::bind tries to act on the
placeholder:
void f(decltype(std::placeholders::_1));
std::thread(t, std::placeholders::_1);