This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/49668] New: [C++0x] std::thread does not forward its args as rvalues


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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]