Index: include/future =================================================================== --- include/future +++ include/future @@ -779,9 +779,12 @@ { if (this->__state_ & base::__constructed) reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); - typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_); + typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _A; + typedef allocator_traits<_A> _ATraits; + typedef pointer_traits _PTraits; + _A __a(__alloc_); this->~__assoc_state_alloc(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template @@ -802,9 +805,12 @@ void __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT { - typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_); + typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _A; + typedef allocator_traits<_A> _ATraits; + typedef pointer_traits _PTraits; + _A __a(__alloc_); this->~__assoc_state_alloc(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template @@ -825,9 +831,12 @@ void __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT { - typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_); + typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _A; + typedef allocator_traits<_A> _ATraits; + typedef pointer_traits _PTraits; + _A __a(__alloc_); this->~__assoc_sub_state_alloc(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template @@ -1410,12 +1419,13 @@ template promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) { - typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp, _Alloc> >::other _A2; + typedef __assoc_state_alloc<_Rp, _Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); - unique_ptr<__assoc_state_alloc<_Rp, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(__hold.get()) __assoc_state_alloc<_Rp, _Alloc>(__a0); - __state_ = __hold.release(); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); } template @@ -1583,12 +1593,13 @@ template promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) { - typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp&, _Alloc> >::other _A2; + typedef __assoc_state_alloc<_Rp&, _Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); - unique_ptr<__assoc_state_alloc<_Rp&, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(__hold.get()) __assoc_state_alloc<_Rp&, _Alloc>(__a0); - __state_ = __hold.release(); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); } template @@ -1719,12 +1730,13 @@ template promise::promise(allocator_arg_t, const _Alloc& __a0) { - typedef typename _Alloc::template rebind<__assoc_sub_state_alloc<_Alloc> >::other _A2; + typedef __assoc_sub_state_alloc<_Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); - unique_ptr<__assoc_sub_state_alloc<_Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(__hold.get()) __assoc_sub_state_alloc<_Alloc>(__a0); - __state_ = __hold.release(); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); } template @@ -1804,10 +1816,12 @@ void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() { - typedef typename _Alloc::template rebind<__packaged_task_func>::other _Ap; + typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; + typedef allocator_traits<_Ap> _ATraits; + typedef pointer_traits _PTraits; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template @@ -1896,7 +1910,6 @@ allocator_arg_t, const _Alloc& __a0, _Fp&& __f) : __f_(nullptr) { - typedef allocator_traits<_Alloc> __alloc_traits; typedef typename remove_reference::type>::type _FR; typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1906,18 +1919,13 @@ } else { - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); - __f_ = __hold.release(); + ::new (static_cast(_VSTD::addressof(*__hold.get()))) + _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); + __f_ = _VSTD::addressof(*__hold.release()); } } Index: test/thread/futures/futures.promise/alloc_ctor.pass.cpp =================================================================== --- test/thread/futures/futures.promise/alloc_ctor.pass.cpp +++ test/thread/futures/futures.promise/alloc_ctor.pass.cpp @@ -18,6 +18,7 @@ #include #include "../test_allocator.h" +#include "min_allocator.h" int main() { @@ -46,4 +47,36 @@ assert(f.valid()); } assert(test_alloc_base::count == 0); + // Test with a minimal allocator + { + std::promise p(std::allocator_arg, bare_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } + { + std::promise p(std::allocator_arg, bare_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } + { + std::promise p(std::allocator_arg, bare_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } + // Test with a minimal allocator that returns class-type pointers + { + std::promise p(std::allocator_arg, min_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } + { + std::promise p(std::allocator_arg, min_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } + { + std::promise p(std::allocator_arg, min_allocator()); + std::future f = p.get_future(); + assert(f.valid()); + } } Index: test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp =================================================================== --- test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp +++ test/thread/futures/futures.tas/futures.task.members/ctor_func_alloc.pass.cpp @@ -18,6 +18,7 @@ #include #include "../../test_allocator.h" +#include "min_allocator.h" class A { @@ -92,4 +93,30 @@ assert(f.get() == 4); } assert(test_alloc_base::count == 0); + A::n_copies = 0; + A::n_moves = 0; + { + std::packaged_task p(std::allocator_arg, + bare_allocator(), A(5)); + assert(p.valid()); + std::future f = p.get_future(); + p(3, 'a'); + assert(f.get() == 105.0); + assert(A::n_copies == 0); + assert(A::n_moves > 0); + } + A::n_copies = 0; + A::n_moves = 0; + { + std::packaged_task p(std::allocator_arg, + min_allocator(), A(5)); + assert(p.valid()); + std::future f = p.get_future(); + p(3, 'a'); + assert(f.get() == 105.0); + assert(A::n_copies == 0); + assert(A::n_moves > 0); + } + A::n_copies = 0; + A::n_moves = 0; }