Bug 56492 - std::packaged_task requires CopyConstructible stored task
Summary: std::packaged_task requires CopyConstructible stored task
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-03-01 10:43 UTC by Jonathan Wakely
Modified: 2013-03-16 02:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-03-01 00:00:00


Attachments
Patch for after trunk reopens for 4.9 (3.71 KB, patch)
2013-03-06 20:08 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2013-03-01 10:43:57 UTC
This is rejected because std::packaged_task uses std::function internally and std::function requires a CopyConstructible target object:

#include <future>

struct S
{
  S() = default;
  S(S&&) = default;
  void operator()() { }
};

std::packaged_task<void ()> pt{ S{} };


It's not necessary to use std::function, the _Task_state type could hold the stored task directly, which would allow it to be move constructed.
Comment 1 Jonathan Wakely 2013-03-01 10:45:01 UTC
mine
Comment 2 Jonathan Wakely 2013-03-06 20:08:55 UTC
Created attachment 29600 [details]
Patch for after trunk reopens for 4.9
Comment 3 Jonathan Wakely 2013-03-16 02:48:14 UTC
Author: redi
Date: Sat Mar 16 02:48:06 2013
New Revision: 196695

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196695
Log:
	PR libstdc++/56492
	* include/std/future (__future_base::_Result): Add result_type
	typedef.
	(__future_base::_S_allocate_result): Overload for std::allocator.
	(__future_base::_Task_setter): Use _Result::result_type instead of
	deducing the type from the task.
	(__future_base::_Task_state): Store allocator to allow shared state
	to be reset.  Replace std::function with member of target object type
	accessed via ...
	(__future_base::_Task_state_base): New abstract base class.
	(__future_base::_Task_state_base::_M_run): New virtual function to
	invoke type-erased target object.
	(__future_base::_Task_state_base::_M_reset): New virtual function to
	create new shared_state using same target object and allocator.
	(__future_base::__create_task_state): Allocate a new _Task_state.
	(packaged_task::packaged_task): Use __create_task_state.
	(packaged_task::reset): Use _Task_state_base::_M_reset.
	* testsuite/30_threads/packaged_task/cons/56492.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/30_threads/packaged_task/cons/56492.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/future
Comment 4 Jonathan Wakely 2013-03-16 02:52:17 UTC
fixed