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|","16.0" "`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 @@ -571,6 +571,18 @@ __cntrl_->__add_shared(); } +// LWG-2996 +// We don't backport because it is an evolutionary change. +#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_), @@ -1353,6 +1365,15 @@ typename shared_ptr<_Tp>::element_type*>(__r.get())); } +// LWG-2996 +// We don't backport because it is an evolutionary change. +#if _LIBCPP_STD_VER >= 20 +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> static_pointer_cast(shared_ptr<_Up>&& __r) noexcept { + return shared_ptr<_Tp>(std::move(__r), static_cast::element_type*>(__r.get())); +} +#endif + template inline _LIBCPP_INLINE_VISIBILITY shared_ptr<_Tp> @@ -1363,6 +1384,16 @@ return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); } +// LWG-2996 +// We don't backport because it is an evolutionary change. +#if _LIBCPP_STD_VER >= 20 +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> dynamic_pointer_cast(shared_ptr<_Up>&& __r) noexcept { + auto* __p = dynamic_cast::element_type*>(__r.get()); + return __p ? shared_ptr<_Tp>(std::move(__r), __p) : shared_ptr<_Tp>(); +} +#endif + template _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT @@ -1371,6 +1402,15 @@ return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); } +// LWG-2996 +// We don't backport because it is an evolutionary change. +#if _LIBCPP_STD_VER >= 20 +template +_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(shared_ptr<_Up>&& __r) noexcept { + return shared_ptr<_Tp>(std::move(__r), const_cast::element_type*>(__r.get())); +} +#endif + template _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT @@ -1380,6 +1420,15 @@ typename shared_ptr<_Tp>::element_type*>(__r.get())); } +// LWG-2996 +// We don't backport because it is an evolutionary change. +#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>(std::move(__r), reinterpret_cast::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 @@ -10,11 +10,13 @@ // shared_ptr -// template shared_ptr const_pointer_cast(const shared_ptr& r); +// template shared_ptr const_pointer_cast(const shared_ptr& r) noexcept; +// template shared_ptr const_pointer_cast(shared_ptr&& r) noexcept; +#include #include #include -#include +#include #include "test_macros.h" @@ -45,6 +47,7 @@ { { const std::shared_ptr pA(new A); + ASSERT_NOEXCEPT(std::const_pointer_cast(pA)); std::shared_ptr pB = std::const_pointer_cast(pA); assert(pB.get() == pA.get()); assert(!pB.owner_before(pA) && !pA.owner_before(pB)); @@ -63,6 +66,17 @@ 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); + ASSERT_NOEXCEPT(std::const_pointer_cast(std::move(pA))); + 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 @@ -10,13 +10,15 @@ // shared_ptr -// template shared_ptr dynamic_pointer_cast(const shared_ptr& r); +// template shared_ptr dynamic_pointer_cast(const shared_ptr& r) noexcept; +// template shared_ptr dynamic_pointer_cast(shared_ptr&& r) noexcept; // UNSUPPORTED: no-rtti +#include #include #include -#include +#include #include "test_macros.h" @@ -47,6 +49,7 @@ { { const std::shared_ptr pB(new A); + ASSERT_NOEXCEPT(std::dynamic_pointer_cast(pB)); std::shared_ptr pA = std::dynamic_pointer_cast(pB); assert(pA.get() == pB.get()); assert(!pB.owner_before(pA) && !pA.owner_before(pB)); @@ -65,6 +68,17 @@ 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); + ASSERT_NOEXCEPT(std::dynamic_pointer_cast(std::move(pB))); + 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; @@ -29,6 +32,7 @@ int main(int, char**) { { const std::shared_ptr pA(new A); + ASSERT_NOEXCEPT(std::reinterpret_pointer_cast(pA)); std::shared_ptr pi = std::reinterpret_pointer_cast(pA); std::shared_ptr pA2 = std::reinterpret_pointer_cast(pi); assert(pA2.get() == pA.get()); @@ -70,6 +74,20 @@ 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); + ASSERT_NOEXCEPT(std::reinterpret_pointer_cast(std::move(pA))); + 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 @@ -10,11 +10,13 @@ // shared_ptr -// template shared_ptr static_pointer_cast(const shared_ptr& r); +// template shared_ptr static_pointer_cast(const shared_ptr& r) noexcept; +// template shared_ptr static_pointer_cast(shared_ptr&& r) noexcept; +#include #include #include -#include +#include #include "test_macros.h" @@ -45,6 +47,7 @@ { { const std::shared_ptr pA(new A); + ASSERT_NOEXCEPT(std::static_pointer_cast(pA)); std::shared_ptr pB = std::static_pointer_cast(pA); assert(pB.get() == pA.get()); assert(!pB.owner_before(pA) && !pA.owner_before(pB)); @@ -81,6 +84,17 @@ 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); + ASSERT_NOEXCEPT(std::static_pointer_cast(std::move(pA))); + 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,23 +96,23 @@ } #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 only implemented in c++20 and beyond. + // We don't backport because it is an evolutionary change. { B b; std::shared_ptr pB(std::move(pA), &b); assert(A::count == 1); assert(B::count == 1); - assert(pA.use_count() == 2); - assert(pB.use_count() == 2); + assert(pA.use_count() == 0); + assert(pB.use_count() == 1); assert(pB.get() == &b); } - 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);