Define std::__to_address helper
* include/bits/allocated_ptr.h (__allocated_ptr::get): Use __to_address. (__allocated_ptr::_S_raw_ptr): Remove. * include/bits/forward_list.h (_Fwd_list_base::_M_get_node): Use __to_address. * include/bits/hashtable_policy.h (_Hashtable_alloc): Likewise. * include/bits/ptr_traits.h (__to_address): Define new function template. * include/bits/shared_ptr_base.h (__shared_ptr): Use __to_address. (__shared_ptr::_S_raw_ptr): Remove. * include/bits/stl_vector.h [__cplusplus >= 201103L] (vector::_M_data_ptr): Use __to_address. [__cplusplus < 201103L] (vector::_M_data_ptr): Don't dereference possibly invalid pointers. * include/ext/alloc_traits.h (__alloc_traits::construct) (__alloc_traits::destroy): Use __to_address. From-SVN: r252055
This commit is contained in:
parent
bc03ac3218
commit
2af96386a6
@ -1,3 +1,22 @@
|
||||
2017-09-13 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/bits/allocated_ptr.h (__allocated_ptr::get): Use
|
||||
__to_address.
|
||||
(__allocated_ptr::_S_raw_ptr): Remove.
|
||||
* include/bits/forward_list.h (_Fwd_list_base::_M_get_node): Use
|
||||
__to_address.
|
||||
* include/bits/hashtable_policy.h (_Hashtable_alloc): Likewise.
|
||||
* include/bits/ptr_traits.h (__to_address): Define new function
|
||||
template.
|
||||
* include/bits/shared_ptr_base.h (__shared_ptr): Use __to_address.
|
||||
(__shared_ptr::_S_raw_ptr): Remove.
|
||||
* include/bits/stl_vector.h [__cplusplus >= 201103L]
|
||||
(vector::_M_data_ptr): Use __to_address.
|
||||
[__cplusplus < 201103L] (vector::_M_data_ptr): Don't dereference
|
||||
possibly invalid pointers.
|
||||
* include/ext/alloc_traits.h (__alloc_traits::construct)
|
||||
(__alloc_traits::destroy): Use __to_address.
|
||||
|
||||
2017-09-12 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/79433
|
||||
|
@ -82,16 +82,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
}
|
||||
|
||||
/// Get the address that the owned pointer refers to.
|
||||
value_type* get() { return _S_raw_ptr(_M_ptr); }
|
||||
value_type* get() { return std::__to_address(_M_ptr); }
|
||||
|
||||
private:
|
||||
static value_type* _S_raw_ptr(value_type* __ptr) { return __ptr; }
|
||||
|
||||
template<typename _Ptr>
|
||||
static auto
|
||||
_S_raw_ptr(_Ptr __ptr) -> decltype(_S_raw_ptr(__ptr.operator->()))
|
||||
{ return _S_raw_ptr(__ptr.operator->()); }
|
||||
|
||||
_Alloc* _M_alloc;
|
||||
pointer _M_ptr;
|
||||
};
|
||||
|
@ -336,7 +336,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
||||
_M_get_node()
|
||||
{
|
||||
auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
|
||||
return std::__addressof(*__ptr);
|
||||
return std::__to_address(__ptr);
|
||||
}
|
||||
|
||||
template<typename... _Args>
|
||||
|
@ -2048,7 +2048,7 @@ namespace __detail
|
||||
_Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
|
||||
{
|
||||
auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
|
||||
__node_type* __n = std::__addressof(*__nptr);
|
||||
__node_type* __n = std::__to_address(__nptr);
|
||||
__try
|
||||
{
|
||||
::new ((void*)__n) __node_type;
|
||||
@ -2094,7 +2094,7 @@ namespace __detail
|
||||
__bucket_alloc_type __alloc(_M_node_allocator());
|
||||
|
||||
auto __ptr = __bucket_alloc_traits::allocate(__alloc, __n);
|
||||
__bucket_type* __p = std::__addressof(*__ptr);
|
||||
__bucket_type* __p = std::__to_address(__ptr);
|
||||
__builtin_memset(__p, 0, __n * sizeof(__bucket_type));
|
||||
return __p;
|
||||
}
|
||||
|
@ -146,6 +146,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
template<typename _Ptr, typename _Tp>
|
||||
using __ptr_rebind = typename pointer_traits<_Ptr>::template rebind<_Tp>;
|
||||
|
||||
template<typename _Tp>
|
||||
constexpr _Tp*
|
||||
__to_address(_Tp* __ptr) noexcept
|
||||
{ return __ptr; }
|
||||
|
||||
template<typename _Ptr>
|
||||
constexpr typename std::pointer_traits<_Ptr>::element_type*
|
||||
__to_address(const _Ptr& __ptr)
|
||||
{ return std::__to_address(__ptr.operator->()); }
|
||||
|
||||
_GLIBCXX_END_NAMESPACE_VERSION
|
||||
} // namespace std
|
||||
|
||||
|
@ -1185,7 +1185,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
__shared_ptr(unique_ptr<_Yp, _Del>&& __r)
|
||||
: _M_ptr(__r.get()), _M_refcount()
|
||||
{
|
||||
auto __raw = _S_raw_ptr(__r.get());
|
||||
auto __raw = __to_address(__r.get());
|
||||
_M_refcount = __shared_count<_Lp>(std::move(__r));
|
||||
_M_enable_shared_from_this_with(__raw);
|
||||
}
|
||||
@ -1201,7 +1201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
__shared_ptr(unique_ptr<_Tp1, _Del>&& __r, __sp_array_delete)
|
||||
: _M_ptr(__r.get()), _M_refcount()
|
||||
{
|
||||
auto __raw = _S_raw_ptr(__r.get());
|
||||
auto __raw = __to_address(__r.get());
|
||||
_M_refcount = __shared_count<_Lp>(std::move(__r));
|
||||
_M_enable_shared_from_this_with(__raw);
|
||||
}
|
||||
@ -1386,16 +1386,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
_M_get_deleter(const std::type_info& __ti) const noexcept
|
||||
{ return _M_refcount._M_get_deleter(__ti); }
|
||||
|
||||
template<typename _Tp1>
|
||||
static _Tp1*
|
||||
_S_raw_ptr(_Tp1* __ptr)
|
||||
{ return __ptr; }
|
||||
|
||||
template<typename _Tp1>
|
||||
static auto
|
||||
_S_raw_ptr(_Tp1 __ptr) -> decltype(std::__addressof(*__ptr))
|
||||
{ return std::__addressof(*__ptr); }
|
||||
|
||||
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
|
||||
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
|
||||
|
||||
|
@ -1695,7 +1695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
||||
template<typename _Ptr>
|
||||
typename std::pointer_traits<_Ptr>::element_type*
|
||||
_M_data_ptr(_Ptr __ptr) const
|
||||
{ return empty() ? nullptr : std::__addressof(*__ptr); }
|
||||
{ return empty() ? nullptr : std::__to_address(__ptr); }
|
||||
#else
|
||||
template<typename _Up>
|
||||
_Up*
|
||||
@ -1705,12 +1705,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
||||
template<typename _Ptr>
|
||||
value_type*
|
||||
_M_data_ptr(_Ptr __ptr)
|
||||
{ return __ptr.operator->(); }
|
||||
{ return empty() ? (value_type*)0 : __ptr.operator->(); }
|
||||
|
||||
template<typename _Ptr>
|
||||
const value_type*
|
||||
_M_data_ptr(_Ptr __ptr) const
|
||||
{ return __ptr.operator->(); }
|
||||
{ return empty() ? (const value_type*)0 : __ptr.operator->(); }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -81,7 +81,7 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
|
||||
static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
|
||||
construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
|
||||
{
|
||||
_Base_type::construct(__a, std::addressof(*__p),
|
||||
_Base_type::construct(__a, std::__to_address(__p),
|
||||
std::forward<_Args>(__args)...);
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
|
||||
template<typename _Ptr>
|
||||
static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
|
||||
destroy(_Alloc& __a, _Ptr __p)
|
||||
{ _Base_type::destroy(__a, std::addressof(*__p)); }
|
||||
{ _Base_type::destroy(__a, std::__to_address(__p)); }
|
||||
|
||||
static _Alloc _S_select_on_copy(const _Alloc& __a)
|
||||
{ return _Base_type::select_on_container_copy_construction(__a); }
|
||||
|
Loading…
Reference in New Issue
Block a user