Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -1639,7 +1639,7 @@ struct __rebind_alloc_helper { #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - typedef typename _Traits::template rebind_alloc<_Tp> type; + typedef typename _Traits::template rebind_alloc<_Tp> type; #else typedef typename _Traits::template rebind_alloc<_Tp>::other type; #endif @@ -4274,9 +4274,16 @@ >::type) : __ptr_(__r.get()) { - typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); - __enable_weak_this(__r.get()); +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); + __enable_weak_this(__r.get()); + } __r.release(); } @@ -4296,11 +4303,18 @@ >::type) : __ptr_(__r.get()) { - typedef __shared_ptr_pointer<_Yp*, - reference_wrapper::type>, - allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); - __enable_weak_this(__r.get()); +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef __shared_ptr_pointer<_Yp*, + reference_wrapper::type>, + allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); + __enable_weak_this(__r.get()); + } __r.release(); } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp @@ -67,7 +67,7 @@ pB = std::move(pA); assert(B::count == 0); assert(A::count == 0); - assert(pB.use_count() == 1); +// assert(pB.use_count() == 1); // no longer true due to LWG 2415 assert(pA.get() == 0); assert(pB.get() == ptrA); } @@ -101,7 +101,7 @@ pB = std::move(pA); assert(B::count == 0); assert(A::count == 0); - assert(pB.use_count() == 1); +// assert(pB.use_count() == 1); // no longer true due to LWG 2415 assert(pA.get() == 0); assert(pB.get() == ptrA); } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -58,6 +58,9 @@ void fn ( const std::shared_ptr &) {} void fn ( const std::shared_ptr &) { assert (false); } +template +void assert_deleter ( T * ) { assert(false); } + int main() { { @@ -100,4 +103,13 @@ throw_next = false; fn(std::unique_ptr(new int)); } + +#if __cplusplus >= 201402L + // LWG 2415 + { + std::unique_ptr p(nullptr, assert_deleter); + std::shared_ptr p2(std::move(p)); // should not call deleter when going out of scope + } +#endif + }