diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -3585,7 +3585,7 @@ _NOEXCEPT; #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template explicit shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if::value, __nat>::type= __nat()); + typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat>::type= __nat()); #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template @@ -4529,7 +4529,12 @@ class _LIBCPP_TEMPLATE_VIS weak_ptr { public: +#if _LIBCPP_STD_VER > 14 + typedef remove_extent_t<_Tp> element_type; +#else typedef _Tp element_type; +#endif + private: element_type* __ptr_; __shared_weak_count* __cntrl_; @@ -4560,7 +4565,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr& >::type _LIBCPP_INLINE_VISIBILITY @@ -4573,7 +4578,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr& >::type _LIBCPP_INLINE_VISIBILITY @@ -4584,7 +4589,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr& >::type _LIBCPP_INLINE_VISIBILITY @@ -4713,7 +4718,7 @@ inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr<_Tp>& >::type weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT @@ -4738,7 +4743,7 @@ inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr<_Tp>& >::type weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT @@ -4754,7 +4759,7 @@ inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + __compatible_with<_Yp, _Tp>::value, weak_ptr<_Tp>& >::type weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT @@ -4791,7 +4796,7 @@ template template shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat>::type) : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) { diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp @@ -82,5 +82,47 @@ assert(A::count == 0); #endif +#if STD_TEST_VERSION > 14 + { + std::shared_ptr sp0(new A[4]); + std::weak_ptr wp(sp0); + std::shared_ptr sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 4); + } + assert(A::count == 0); + + { + std::shared_ptr sp0(new A[4]); + std::weak_ptr wp(sp0); + std::shared_ptr sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 4); + } + assert(A::count == 0); + + { + std::shared_ptr sp0(new A[4]); + std::weak_ptr wp(sp0); + std::shared_ptr sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 4); + } + assert(A::count == 0); + + { + std::shared_ptr sp0(new A[4]); + std::weak_ptr wp(sp0); + std::shared_ptr sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 4); + } + assert(A::count == 0); +#endif // STD_TEST_VERSION > 14 + return 0; } diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -481,7 +481,7 @@ 2873Add noexcept to several shared_ptr related functionsKonaComplete 2874Constructor shared_ptr::shared_ptr(Y*) should be constrainedKona 2875shared_ptr::shared_ptr(Y*, D, […]) constructors should be constrainedKona - 2876shared_ptr::shared_ptr(const weak_ptr<Y>&) constructor should be constrainedKona + 2876shared_ptr::shared_ptr(const weak_ptr<Y>&) constructor should be constrainedKonaComplete 2878Missing DefaultConstructible requirement for istream_iterator default constructorKonaComplete 2890The definition of 'object state' applies only to class typesKonaComplete 2900The copy and move constructors of optional are not constexprKonaComplete