|
30 | 30 | #include <__memory/compressed_pair.h> |
31 | 31 | #include <__memory/construct_at.h> |
32 | 32 | #include <__memory/pointer_traits.h> |
| 33 | +#include <__memory/tombstone_traits.h> |
33 | 34 | #include <__memory/uninitialized_algorithms.h> |
34 | 35 | #include <__memory/unique_ptr.h> |
35 | 36 | #include <__type_traits/add_lvalue_reference.h> |
@@ -824,14 +825,24 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr { |
824 | 825 | friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
825 | 826 | template <class _Up> |
826 | 827 | friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
| 828 | + |
| 829 | + friend struct __tombstone_traits<shared_ptr<_Tp>>; |
827 | 830 | }; |
828 | 831 |
|
829 | 832 | #if _LIBCPP_STD_VER >= 17 |
830 | 833 | template <class _Tp> |
831 | 834 | shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; |
832 | 835 | template <class _Tp, class _Dp> |
833 | 836 | shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; |
834 | | -#endif |
| 837 | + |
| 838 | +template <class _Tp> |
| 839 | +struct __tombstone_traits<shared_ptr<_Tp>> { |
| 840 | + static constexpr auto __disengaged_value_ = __tombstone_traits_assume_aligned_pointer::__disengaged_value_; |
| 841 | + static constexpr size_t __is_disengaged_offset_ = |
| 842 | + __builtin_offsetof(shared_ptr<_Tp>, __cntrl_) + |
| 843 | + __tombstone_traits_assume_aligned_pointer::__is_disengaged_offset_; |
| 844 | +}; |
| 845 | +#endif // _LIBCPP_STD_VER >= 17 |
835 | 846 |
|
836 | 847 | // |
837 | 848 | // std::allocate_shared and std::make_shared |
@@ -1376,12 +1387,21 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr { |
1376 | 1387 | friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
1377 | 1388 | template <class _Up> |
1378 | 1389 | friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
| 1390 | + |
| 1391 | + friend struct __tombstone_traits<weak_ptr<_Tp>>; |
1379 | 1392 | }; |
1380 | 1393 |
|
1381 | 1394 | #if _LIBCPP_STD_VER >= 17 |
1382 | 1395 | template <class _Tp> |
1383 | 1396 | weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; |
1384 | | -#endif |
| 1397 | + |
| 1398 | +template <class _Tp> |
| 1399 | +struct __tombstone_traits<weak_ptr<_Tp>> { |
| 1400 | + static constexpr auto __disengaged_value_ = __tombstone_traits_assume_aligned_pointer::__disengaged_value_; |
| 1401 | + static constexpr size_t __is_disengaged_offset_ = |
| 1402 | + __builtin_offsetof(weak_ptr<_Tp>, __cntrl_) + __tombstone_traits_assume_aligned_pointer::__is_disengaged_offset_; |
| 1403 | +}; |
| 1404 | +#endif // _LIBCPP_STD_VER >= 17 |
1385 | 1405 |
|
1386 | 1406 | template <class _Tp> |
1387 | 1407 | inline _LIBCPP_CONSTEXPR weak_ptr<_Tp>::weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} |
|
0 commit comments