[libcxx-commits] [PATCH] D135548: [libc++] Implement c++20 shared_ptr rvalue overloads.
Deev Patel via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 9 22:13:23 PDT 2022
pateldeev updated this revision to Diff 466420.
pateldeev added a comment.
Unit tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135548/new/
https://reviews.llvm.org/D135548
Files:
libcxx/include/__memory/shared_ptr.h
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
Index: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
===================================================================
--- libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
+++ 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<A> 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<B> 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<B> 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);
Index: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp
===================================================================
--- libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp
+++ 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<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(std::move(pA));
assert(pA.get() == nullptr);
- assert(pB.get() == pA_raw);
+ assert(pB.get() == static_cast<B*>(pA_raw));
assert(pB.use_count() == 1);
}
#endif // TEST_STD_VER > 20
Index: libcxx/include/__memory/shared_ptr.h
===================================================================
--- libcxx/include/__memory/shared_ptr.h
+++ libcxx/include/__memory/shared_ptr.h
@@ -1386,7 +1386,7 @@
#if _LIBCPP_STD_VER > 20
template <class _Tp, class _Up>
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<typename shared_ptr<_Tp>::element_type*>(__r.get()));
}
#endif
@@ -1419,7 +1419,7 @@
#if _LIBCPP_STD_VER > 20
template <class _Tp, class _Up>
-_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 <class _Tp, class _Up>
-_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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135548.466420.patch
Type: text/x-patch
Size: 3497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221010/5232b114/attachment.bin>
More information about the libcxx-commits
mailing list