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: r...@gcc.gnu.org
        ReportedBy: r...@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);

Reply via email to