+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
}
/// 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;
};
_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>
_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;
__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;
}
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
__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);
}
__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);
}
_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;
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*
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
};
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)...);
}
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); }