Skip to content

Commit 9e739a7

Browse files
committed
[libc++] Require fancy pointer to be correctly convertible
1 parent 37fe7a9 commit 9e739a7

File tree

5 files changed

+99
-114
lines changed

5 files changed

+99
-114
lines changed

libcxx/include/__hash_table

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct __hash_node_base {
9696
__next_pointer __next_;
9797

9898
_LIBCPP_HIDE_FROM_ABI __next_pointer __ptr() _NOEXCEPT {
99-
return static_cast<__next_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this));
99+
return pointer_traits<__node_base_pointer>::pointer_to(*this);
100100
}
101101

102102
_LIBCPP_HIDE_FROM_ABI __node_pointer __upcast() _NOEXCEPT {
@@ -1499,9 +1499,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(const_iterator __p
14991499
while (__pp->__next_ != __np)
15001500
__pp = __pp->__next_;
15011501
__cp->__next_ = __np;
1502-
__pp->__next_ = static_cast<__next_pointer>(__cp);
1502+
__pp->__next_ = __cp;
15031503
++size();
1504-
return iterator(static_cast<__next_pointer>(__cp));
1504+
return iterator(__cp);
15051505
}
15061506
return __node_insert_multi(__cp);
15071507
}
@@ -1547,9 +1547,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const&
15471547
__bucket_list_[std::__constrain_hash(__h->__next_->__hash(), __bc)] = __h.get()->__ptr();
15481548
} else {
15491549
__h->__next_ = __pn->__next_;
1550-
__pn->__next_ = static_cast<__next_pointer>(__h.get());
1550+
__pn->__next_ = __h.get();
15511551
}
1552-
__nd = static_cast<__next_pointer>(__h.release());
1552+
__nd = __h.release();
15531553
// increment size
15541554
++size();
15551555
__inserted = true;

libcxx/include/__memory/pointer_traits.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,6 @@ concept __resettable_smart_pointer_with_args = requires(_Smart __s, _Pointer __p
252252

253253
#endif
254254

255-
// This function ensures safe conversions between fancy pointers at compile-time, where we avoid casts from/to
256-
// `__void_pointer` by obtaining the underlying raw pointer from the fancy pointer using `std::to_address`,
257-
// then dereferencing it to retrieve the pointed-to object, and finally constructing the target fancy pointer
258-
// to that object using the `std::pointer_traits<>::pinter_to` function.
259-
template <class _PtrTo, class _PtrFrom>
260-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _PtrTo __static_fancy_pointer_cast(const _PtrFrom& __p) {
261-
using __ptr_traits = pointer_traits<_PtrTo>;
262-
using __element_type = typename __ptr_traits::element_type;
263-
return __p ? __ptr_traits::pointer_to(*static_cast<__element_type*>(std::addressof(*__p)))
264-
: static_cast<_PtrTo>(nullptr);
265-
}
266-
267255
_LIBCPP_END_NAMESPACE_STD
268256

269257
_LIBCPP_POP_MACROS

0 commit comments

Comments
 (0)