|
32 | 32 | #include <__memory/destroy.h> |
33 | 33 | #include <__memory/pointer_traits.h> |
34 | 34 | #include <__memory/shared_count.h> |
| 35 | +#include <__memory/tombstone_traits.h> |
35 | 36 | #include <__memory/uninitialized_algorithms.h> |
36 | 37 | #include <__memory/unique_ptr.h> |
37 | 38 | #include <__type_traits/add_reference.h> |
@@ -689,14 +690,25 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr { |
689 | 690 | friend class shared_ptr; |
690 | 691 | template <class _Up> |
691 | 692 | friend class weak_ptr; |
| 693 | + |
| 694 | + friend struct __tombstone_traits<shared_ptr<_Tp> >; |
692 | 695 | }; |
693 | 696 |
|
694 | | -#if _LIBCPP_STD_VER >= 17 |
| 697 | +#if _LIBCPP_STD_VER >= 17 && 0 |
695 | 698 | template <class _Tp> |
696 | 699 | shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; |
697 | 700 | template <class _Tp, class _Dp> |
698 | 701 | shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; |
699 | | -#endif |
| 702 | + |
| 703 | +template <class _Tp> |
| 704 | +struct __tombstone_traits<shared_ptr<_Tp>> { |
| 705 | + static constexpr auto __disengaged_value_ = |
| 706 | + __tombstone_traits_assume_aligned_pointer<__shared_weak_count*>::__disengaged_value_; |
| 707 | + static constexpr size_t __is_disengaged_offset_ = |
| 708 | + __builtin_offsetof(shared_ptr<_Tp>, __cntrl_) + |
| 709 | + __tombstone_traits_assume_aligned_pointer<__shared_weak_count*>::__is_disengaged_offset_; |
| 710 | +}; |
| 711 | +#endif // _LIBCPP_STD_VER >= 17 |
700 | 712 |
|
701 | 713 | // |
702 | 714 | // std::allocate_shared and std::make_shared |
@@ -1242,12 +1254,19 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI weak_ptr { |
1242 | 1254 | friend class weak_ptr; |
1243 | 1255 | template <class _Up> |
1244 | 1256 | friend class shared_ptr; |
| 1257 | + |
| 1258 | + friend struct __tombstone_traits<weak_ptr<_Tp> >; |
1245 | 1259 | }; |
1246 | 1260 |
|
1247 | 1261 | #if _LIBCPP_STD_VER >= 17 |
1248 | 1262 | template <class _Tp> |
1249 | 1263 | weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; |
1250 | | -#endif |
| 1264 | + |
| 1265 | +template <class _Tp> |
| 1266 | +struct __tombstone_traits<weak_ptr<_Tp>> { |
| 1267 | + |
| 1268 | +}; |
| 1269 | +#endif // _LIBCPP_STD_VER >= 17 |
1251 | 1270 |
|
1252 | 1271 | template <class _Tp> |
1253 | 1272 | inline _LIBCPP_CONSTEXPR weak_ptr<_Tp>::weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} |
|
0 commit comments