diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv --- a/libcxx/docs/Status/Cxx20Issues.csv +++ b/libcxx/docs/Status/Cxx20Issues.csv @@ -102,7 +102,7 @@ "`2943 `__","Problematic specification of the wide version of ``basic_filebuf::open``\ ","San Diego","|Nothing To Do|","" "`2960 `__","[fund.ts.v3] ``nonesuch``\ is insufficiently useless","San Diego","|Complete|","" "`2995 `__","``basic_stringbuf``\ default constructor forbids it from using SSO capacity","San Diego","","" -"`2996 `__","Missing rvalue overloads for ``shared_ptr``\ operations","San Diego","","" +"`2996 `__","Missing rvalue overloads for ``shared_ptr``\ operations","San Diego","|Complete|","" "`3008 `__","``make_shared``\ (sub)object destruction semantics are not specified","San Diego","","" "`3022 `__","``is_convertible``\ may lead to ODR","San Diego","Resolved by 1285R0","" "`3025 `__","Map-like container deduction guides should use ``pair``\ , not ``pair``\ ","San Diego","|Complete|","" diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -591,6 +591,16 @@ __cntrl_->__add_shared(); } +#if _LIBCPP_STD_VER > 20 + template + _LIBCPP_HIDE_FROM_ABI shared_ptr(shared_ptr<_Yp>&& __r, element_type* __p) _NOEXCEPT + : __ptr_(__p), + __cntrl_(__r.__cntrl_) { + __r.__ptr_ = nullptr; + __r.__cntrl_ = nullptr; + } +#endif + _LIBCPP_HIDE_FROM_ABI shared_ptr(const shared_ptr& __r) _NOEXCEPT : __ptr_(__r.__ptr_), @@ -668,7 +678,7 @@ { typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; typedef __shared_ptr_pointer::pointer, _Dp, _AllocT> _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), std::move(__r.get_deleter()), _AllocT()); + __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::move(__r.get_deleter()), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); @@ -1373,6 +1383,13 @@ typename shared_ptr<_Tp>::element_type*>(__r.get())); } +#if _LIBCPP_STD_VER > 20 +template +inline _LIBCPP_INLINE_VISIBILITY shared_ptr<_Tp> static_pointer_cast(shared_ptr<_Up>&& __r) _NOEXCEPT { + return shared_ptr<_Tp>(_VSTD::move(__r), static_cast::element_type*>(__r.get())); +} +#endif + template inline _LIBCPP_INLINE_VISIBILITY shared_ptr<_Tp> @@ -1383,6 +1400,15 @@ return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); } +#if _LIBCPP_STD_VER > 20 +template +inline _LIBCPP_INLINE_VISIBILITY shared_ptr<_Tp> dynamic_pointer_cast(shared_ptr<_Up>&& __r) _NOEXCEPT { + typedef typename shared_ptr<_Tp>::element_type _ET; + _ET* __p = dynamic_cast<_ET*>(__r.get()); + return __p ? shared_ptr<_Tp>(_VSTD::move(__r), __p) : shared_ptr<_Tp>(); +} +#endif + template _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT @@ -1391,6 +1417,15 @@ return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); } +#if _LIBCPP_STD_VER > 20 +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(shared_ptr<_Up>&& __r) _NOEXCEPT { + typedef typename shared_ptr<_Tp>::element_type _RTp; + return shared_ptr<_Tp>(_VSTD::move(__r), const_cast<_RTp*>(__r.get())); +} + +#endif + template _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT @@ -1400,6 +1435,13 @@ typename shared_ptr<_Tp>::element_type*>(__r.get())); } +#if _LIBCPP_STD_VER > 20 +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(shared_ptr<_Up>&& __r) _NOEXCEPT { + return shared_ptr<_Tp>(_VSTD::move(__r), reinterpret_cast< typename shared_ptr<_Tp>::element_type*>(__r.get())); +} +#endif + #ifndef _LIBCPP_NO_RTTI template diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -11,10 +11,12 @@ // shared_ptr // template shared_ptr const_pointer_cast(const shared_ptr& r); +// template shared_ptr const_pointer_cast(shared_ptr&& r); +#include #include #include -#include +#include #include "test_macros.h" @@ -63,6 +65,16 @@ assert(!pB.owner_before(pA) && !pA.owner_before(pB)); } #endif // TEST_STD_VER > 14 +#if TEST_STD_VER > 20 + { + A* pA_raw = new A; + std::shared_ptr pA(pA_raw); + std::shared_ptr pB = std::const_pointer_cast(std::move(pA)); + assert(pA.get() == nullptr); + assert(pB.get() == pA_raw); + assert(pB.use_count() == 1); + } +#endif // TEST_STD_VER > 20 return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp @@ -11,12 +11,14 @@ // shared_ptr // template shared_ptr dynamic_pointer_cast(const shared_ptr& r); +// template shared_ptr dynamic_pointer_cast(shared_ptr&& r); // UNSUPPORTED: no-rtti +#include #include #include -#include +#include #include "test_macros.h" @@ -65,6 +67,16 @@ assert(pA.use_count() == 0); } #endif // TEST_STD_VER > 14 +#if TEST_STD_VER > 20 + { + A* pA_raw = new A; + std::shared_ptr pB(pA_raw); + std::shared_ptr pA = std::dynamic_pointer_cast(std::move(pB)); + assert(pB.get() == nullptr); + assert(pA.get() == pA_raw); + assert(pA.use_count() == 1); + } +#endif // TEST_STD_VER > 20 return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/reinterpret_pointer_cast.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/reinterpret_pointer_cast.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/reinterpret_pointer_cast.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/reinterpret_pointer_cast.pass.cpp @@ -12,12 +12,15 @@ // template // shared_ptr reinterpret_pointer_cast(const shared_ptr& r) noexcept; +// template +// shared_ptr reinterpret_pointer_cast(shared_ptr&& r) noexcept; #include "test_macros.h" +#include #include #include -#include +#include struct A { int x; @@ -70,6 +73,19 @@ assert(!pi.owner_before(pA) && !pA.owner_before(pi)); } #endif // TEST_STD_VER > 14 +#if TEST_STD_VER > 20 + { + A* pA_raw = new A; + std::shared_ptr pA(pA_raw); + std::shared_ptr pi = std::reinterpret_pointer_cast(std::move(pA)); + assert(pA.get() == nullptr); + assert(pi.use_count() == 1); + std::shared_ptr pA2 = std::reinterpret_pointer_cast(std::move(pi)); + assert(pi.get() == nullptr); + assert(pA2.get() == pA_raw); + assert(pA2.use_count() == 1); + } +#endif // TEST_STD_VER > 20 return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp @@ -11,10 +11,12 @@ // shared_ptr // template shared_ptr static_pointer_cast(const shared_ptr& r); +// template shared_ptr static_pointer_cast(shared_ptr&& r); +#include #include #include -#include +#include #include "test_macros.h" @@ -81,6 +83,16 @@ assert(!pB.owner_before(pA) && !pA.owner_before(pB)); } #endif // TEST_STD_VER > 14 +#if TEST_STD_VER > 20 + { + A* pA_raw = new A; + std::shared_ptr pA(pA_raw); + std::shared_ptr pB = std::static_pointer_cast(std::move(pA)); + assert(pA.get() == nullptr); + assert(pB.get() == pA_raw); + assert(pB.use_count() == 1); + } +#endif // TEST_STD_VER > 20 return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -96,11 +96,22 @@ } #if TEST_STD_VER > 17 && defined(_LIBCPP_VERSION) - // This won't pass when LWG-2996 is implemented. { std::shared_ptr pA(new A); assert(pA.use_count() == 1); +# if TEST_STD_VER > 20 + // LWG-2996 is implemented in c++20 and beyond. + { + B b; + std::shared_ptr pB(std::move(pA), &b); + assert(A::count == 1); + assert(B::count == 1); + assert(pA.use_count() == 0); + assert(pB.use_count() == 1); + assert(pB.get() == &b); + } +# else { B b; std::shared_ptr pB(std::move(pA), &b); @@ -113,6 +124,7 @@ assert(pA.use_count() == 1); assert(A::count == 1); assert(B::count == 0); +# endif // TEST_STD_VER > 20 } assert(A::count == 0); assert(B::count == 0);