Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -2696,7 +2696,11 @@ {reset(__p.release()); return *this;} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} + _LIBCPP_INLINE_VISIBILITY ~unique_ptr() + { + if (__ptr_.first() != pointer()) + __ptr_.second()(__ptr_.first()); + } _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT { @@ -2888,7 +2892,11 @@ } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} + _LIBCPP_INLINE_VISIBILITY ~unique_ptr() + { + if (__ptr_.first() != pointer()) + __ptr_.second()(__ptr_.first()); + } _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT { Index: test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/stored_pointer.pass.cpp =================================================================== --- /dev/null +++ test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/stored_pointer.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// ~unique_ptr() should not set the stored pointer to nullptr. + +#include +#include + +struct A; + +struct B +{ + std::unique_ptr a; +}; + +struct A +{ + B* b; + ~A() {assert(b->a);} +}; + +int main() +{ + B b; + b.a.reset(new A); + b.a->b = &b; +}