|
31 | 31 | #include <__memory/construct_at.h> |
32 | 32 | #include <__memory/pointer_traits.h> |
33 | 33 | #include <__memory/shared_count.h> |
| 34 | +#include <__memory/tombstone_traits.h> |
34 | 35 | #include <__memory/uninitialized_algorithms.h> |
35 | 36 | #include <__memory/unique_ptr.h> |
36 | 37 | #include <__type_traits/add_lvalue_reference.h> |
@@ -712,14 +713,24 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr { |
712 | 713 | friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
713 | 714 | template <class _Up> |
714 | 715 | friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
| 716 | + |
| 717 | + friend struct __tombstone_traits<shared_ptr<_Tp> >; |
715 | 718 | }; |
716 | 719 |
|
717 | 720 | #if _LIBCPP_STD_VER >= 17 |
718 | 721 | template <class _Tp> |
719 | 722 | shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; |
720 | 723 | template <class _Tp, class _Dp> |
721 | 724 | shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; |
722 | | -#endif |
| 725 | + |
| 726 | +template <class _Tp> |
| 727 | +struct __tombstone_traits<shared_ptr<_Tp>> { |
| 728 | + static constexpr auto __disengaged_value_ = __tombstone_traits_assume_aligned_pointer::__disengaged_value_; |
| 729 | + static constexpr size_t __is_disengaged_offset_ = |
| 730 | + __builtin_offsetof(shared_ptr<_Tp>, __cntrl_) + |
| 731 | + __tombstone_traits_assume_aligned_pointer::__is_disengaged_offset_; |
| 732 | +}; |
| 733 | +#endif // _LIBCPP_STD_VER >= 17 |
723 | 734 |
|
724 | 735 | // |
725 | 736 | // std::allocate_shared and std::make_shared |
@@ -1264,12 +1275,21 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr { |
1264 | 1275 | friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
1265 | 1276 | template <class _Up> |
1266 | 1277 | friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
| 1278 | + |
| 1279 | + friend struct __tombstone_traits<weak_ptr<_Tp> >; |
1267 | 1280 | }; |
1268 | 1281 |
|
1269 | 1282 | #if _LIBCPP_STD_VER >= 17 |
1270 | 1283 | template <class _Tp> |
1271 | 1284 | weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; |
1272 | | -#endif |
| 1285 | + |
| 1286 | +template <class _Tp> |
| 1287 | +struct __tombstone_traits<weak_ptr<_Tp>> { |
| 1288 | + static constexpr auto __disengaged_value_ = __tombstone_traits_assume_aligned_pointer::__disengaged_value_; |
| 1289 | + static constexpr size_t __is_disengaged_offset_ = |
| 1290 | + __builtin_offsetof(weak_ptr<_Tp>, __cntrl_) + __tombstone_traits_assume_aligned_pointer::__is_disengaged_offset_; |
| 1291 | +}; |
| 1292 | +#endif // _LIBCPP_STD_VER >= 17 |
1273 | 1293 |
|
1274 | 1294 | template <class _Tp> |
1275 | 1295 | inline _LIBCPP_CONSTEXPR weak_ptr<_Tp>::weak_ptr() _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {} |
|
0 commit comments