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 @@ -1386,7 +1386,7 @@ #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< typename shared_ptr<_Tp>::element_type*>(__r.get())); + return shared_ptr<_Tp>(_VSTD::move(__r), static_cast::element_type*>(__r.get())); } #endif @@ -1419,7 +1419,7 @@ #if _LIBCPP_STD_VER > 20 template -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> const_pointer_cast(shared_ptr<_Up>& __r) _NOEXCEPT { +_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())); } @@ -1437,7 +1437,7 @@ #if _LIBCPP_STD_VER > 20 template -_LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(shared_ptr<_Up>& __r) _NOEXCEPT { +_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 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 @@ -89,7 +89,7 @@ std::shared_ptr pA(new A); std::shared_ptr pB = std::static_pointer_cast(std::move(pA)); assert(pA.get() == nullptr); - assert(pB.get() == pA_raw); + assert(pB.get() == static_cast(pA_raw)); assert(pB.use_count() == 1); } #endif // TEST_STD_VER > 20 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);