[v3] implement LWG 2067 and new issues with constructors in future

2011-11-01 Thread Jonathan Wakely
This patch implements
http://lwg.github.com/issues/lwg-active.html#2067 which has Ready
status, as well as fixing two new issues I've reported in the past few
hours.  The first is that packaged_task's template constructors should
be restricted to prevent them from being chosen to copy a
packaged_task object and the second is that promise and packaged_task
should properly support uses-allocator construction so that if
promise(args...) is well-formed then so is promise(allocator_arg,
alloc, args...)

* include/std/future (promise): Add constructors for uses-allocator
construction from rvalue promise.
(packaged_task): Implement LWG 2067. Add additional constructors for
uses-allocator construction.
* testsuite/30_threads/packaged_task/cons/3.cc: New.
* testsuite/30_threads/packaged_task/cons/alloc2.cc: New.
* testsuite/30_threads/promise/cons/alloc2.cc: New.

Tested x86_64-linux, committed to trunk.
Index: include/std/future
===
--- include/std/future	(revision 180749)
+++ include/std/future	(working copy)
@@ -955,6 +955,12 @@
 	  _M_storage(__future_base::_S_allocate_result_Res(__a))
 { }
 
+  templatetypename _Allocator
+promise(allocator_arg_t, const _Allocator, promise __rhs)
+: _M_future(std::move(__rhs._M_future)),
+	  _M_storage(std::move(__rhs._M_storage))
+{ }
+
   promise(const promise) = delete;
 
   ~promise()
@@ -1047,6 +1053,12 @@
 	  _M_storage(__future_base::_S_allocate_result_Res(__a))
 { }
 
+  templatetypename _Allocator
+promise(allocator_arg_t, const _Allocator, promise __rhs)
+: _M_future(std::move(__rhs._M_future)),
+	  _M_storage(std::move(__rhs._M_storage))
+{ }
+
   promise(const promise) = delete;
 
   ~promise()
@@ -1122,6 +1134,12 @@
 	  _M_storage(__future_base::_S_allocate_resultvoid(__a))
 { }
 
+  templatetypename _Allocator
+promise(allocator_arg_t, const _Allocator, promise __rhs)
+: _M_future(std::move(__rhs._M_future)),
+	  _M_storage(std::move(__rhs._M_storage))
+{ }
+
   promise(const promise) = delete;
 
   ~promise()
@@ -1270,6 +1288,15 @@
 { return std::forward_Tp(__t); }
 };
 
+  templatetypename _Task, typename _Fn, bool
+   = is_same_Task, typename remove_reference_Fn::type::value
+struct __is_same_pkgdtask
+{ typedef void __type; };
+
+  templatetypename _Task, typename _Fn
+struct __is_same_pkgdtask_Task, _Fn, true
+{ };
+
   /// packaged_task
   templatetypename _Res, typename... _ArgTypes
 class packaged_task_Res(_ArgTypes...)
@@ -1281,13 +1308,20 @@
   // Construction and destruction
   packaged_task() noexcept { }
 
-  templatetypename _Fn
+  templatetypename _Allocator
 explicit
+packaged_task(allocator_arg_t, const _Allocator __a) noexcept
+{ }
+
+  templatetypename _Fn, typename = typename
+   __is_same_pkgdtaskpackaged_task, _Fn::__type
+explicit
 packaged_task(_Fn __fn)
 : _M_state(std::make_shared_State_type(std::forward_Fn(__fn)))
 { }
 
-  templatetypename _Fn, typename _Allocator
+  templatetypename _Fn, typename _Allocator, typename = typename
+   __is_same_pkgdtaskpackaged_task, _Fn::__type
 explicit
 packaged_task(allocator_arg_t, const _Allocator __a, _Fn __fn)
 : _M_state(std::allocate_shared_State_type(__a,
@@ -1301,13 +1335,24 @@
   }
 
   // No copy
-  packaged_task(packaged_task) = delete;
-  packaged_task operator=(packaged_task) = delete;
+  packaged_task(const packaged_task) = delete;
+  packaged_task operator=(const packaged_task) = delete;
 
+  templatetypename _Allocator
+explicit
+packaged_task(allocator_arg_t, const _Allocator,
+  const packaged_task) = delete;
+
   // Move support
   packaged_task(packaged_task __other) noexcept
   { this-swap(__other); }
 
+  templatetypename _Allocator
+explicit
+packaged_task(allocator_arg_t, const _Allocator,
+  packaged_task __other) noexcept
+{ this-swap(__other); }
+
   packaged_task operator=(packaged_task __other) noexcept
   {
 packaged_task(std::move(__other)).swap(*this);
Index: testsuite/30_threads/packaged_task/cons/alloc2.cc
===
--- testsuite/30_threads/packaged_task/cons/alloc2.cc	(revision 0)
+++ testsuite/30_threads/packaged_task/cons/alloc2.cc	(revision 0)
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// { dg-options -std=gnu++0x }
+// { dg-require-cstdint  }
+// { dg-require-gthreads  }
+// { dg-require-atomic-builtins  }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you 

Re: [v3] implement LWG 2067 and new issues with constructors in future

2011-11-01 Thread Jonathan Wakely
On 2 November 2011 00:53, Jonathan Wakely wrote:
 The first is that packaged_task's template constructors should
 be restricted to prevent them from being chosen to copy a
 packaged_task object

While submitting that issue to the LWG chair I realised the constraint
should use decayFn instead of remove_referenceFn so that it also
removes cv qualifiers.  I'll fix that tomorrow.