http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60564
Bug ID: 60564 Summary: [C++11] The std::packaged_task constructor taking a reference to a functor does not copy its argument. Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: ralph.tandetzky at gmail dot com The following code compiles successfully: ~~~~~~~~~~~~~~~~~~~~~ #include <future> #include <iostream> using namespace std; struct Test { Test() { cout << "constructed." << endl; } Test( const Test & ) { cout << "copied." << endl; } Test( Test && ) { cout << "moved." << endl; } void operator()() const {} }; int main() { Test t; packaged_task<void()> pt1( t ); } ~~~~~~~~~~~~~~~~~~~~~ It produces the following output: ~~~~~~~~~~~~~~~~~~~~~ constructed. moved. ~~~~~~~~~~~~~~~~~~~~~ However, the constructor of std::packaged_task<void()> should copy it's argument into its internally stored task object according to 30.6.9.1 of the C++11 standard (I'm referring to N3485, actually). Settings: I've used the online-compiler of http://en.cppreference.com/ with the compiler GCC 4.8 (C++11). GCC 4.7 (C++11) does not have the bug, but produces a correct output copying the object passed into the constructor.