Fixes #206 ("operator-> on static_vector::iterator causes cast alignment warning")

This commit is contained in:
Ion Gaztañaga committed 2021-12-28 15:17:15 +01:00
1 parent ea3521bf14
commit 3f76f9fdf7
23 files changed
+124 -93

No files matched your search

@@ -33,6 +33,7 @@
#include <boost/container/detail/placement_new.hpp>
#include <boost/container/detail/mpl.hpp>
#include <boost/move/detail/to_raw_pointer.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include <boost/container/detail/type_traits.hpp>
// intrusive
#include <boost/intrusive/pointer_traits.hpp>
@@ -540,7 +541,7 @@ class private_adaptive_node_pool_impl_common
BOOST_ASSERT(hdr_off_holder->hdr_offset == offset);
BOOST_ASSERT(0 == (reinterpret_cast<std::size_t>(hdr_off_holder) & (real_block_alignment - 1)));
BOOST_ASSERT(0 == (hdr_off_holder->hdr_offset & (real_block_alignment - 1)));
hdr_off_holder = reinterpret_cast<hdr_offset_holder *>(reinterpret_cast<char*>(hdr_off_holder) + real_block_alignment);
hdr_off_holder = move_detail::force_ptr<hdr_offset_holder *>(reinterpret_cast<char*>(hdr_off_holder) + real_block_alignment);
}
}
}
@@ -563,7 +564,7 @@ class private_adaptive_node_pool_impl_common
hdr_offset_holder *priv_first_subblock_from_block(block_info_t *block, const size_type num_subblocks, const size_type real_block_alignment, AlignOnlyFalse) const
{
hdr_offset_holder *const hdr_off_holder = reinterpret_cast<hdr_offset_holder*>
hdr_offset_holder *const hdr_off_holder = move_detail::force_ptr<hdr_offset_holder*>
(reinterpret_cast<char*>(block) - (num_subblocks-1)*real_block_alignment);
BOOST_ASSERT(hdr_off_holder->hdr_offset == size_type(reinterpret_cast<char*>(block) - reinterpret_cast<char*>(hdr_off_holder)));
BOOST_ASSERT(0 == ((std::size_t)hdr_off_holder & (real_block_alignment - 1)));
@@ -574,7 +575,7 @@ class private_adaptive_node_pool_impl_common
hdr_offset_holder *priv_first_subblock_from_block(block_info_t *block, const size_type num_subblocks, const size_type real_block_alignment, AlignOnlyTrue) const
{
(void)num_subblocks; (void)real_block_alignment;
return reinterpret_cast<hdr_offset_holder*>(block);
return move_detail::force_ptr<hdr_offset_holder*>(block);
}
void priv_deallocate_free_blocks_impl( const size_type max_free_blocks, const size_type real_num_node
@@ -903,7 +904,7 @@ class private_adaptive_node_pool_impl_common
reinterpret_cast<hdr_offset_holder*>((std::size_t)node & size_type(~(real_block_alignment - 1)));
BOOST_ASSERT(0 == ((std::size_t)hdr_off_holder & (real_block_alignment - 1)));
BOOST_ASSERT(0 == (hdr_off_holder->hdr_offset & (real_block_alignment - 1)));
block_info_t *block = reinterpret_cast<block_info_t *>
block_info_t *block = move_detail::force_ptr<block_info_t *>
(reinterpret_cast<char*>(hdr_off_holder) + hdr_off_holder->hdr_offset);
BOOST_ASSERT(block->hdr_offset == 0);
return block;
+2 -10
View File
@@ -18,21 +18,13 @@
# pragma once
#endif
#include <cstddef>
#include <boost/move/detail/addressof.hpp>
namespace boost {
namespace container {
namespace dtl {
template <typename T>
BOOST_CONTAINER_FORCEINLINE T* addressof(T& obj)
{
return static_cast<T*>(
static_cast<void*>(
const_cast<char*>(
&reinterpret_cast<const volatile char&>(obj)
)));
}
using boost::move_detail::addressof;
} //namespace dtl {
} //namespace container {
@@ -36,7 +36,9 @@
#include <boost/move/detail/fwd_macros.hpp>
#endif
// move
#include <boost/move/utility_core.hpp>
#include <boost/move/detail/force_ptr.hpp>
// other
#include <boost/assert.hpp>
#include <boost/core/no_exceptions_support.hpp>
@@ -129,7 +131,7 @@ struct insert_value_initialized_n_proxy
while (n){
--n;
storage_t v;
value_type *vp = reinterpret_cast<value_type *>(v.data);
value_type *vp = move_detail::force_ptr<value_type *>(static_cast<void *>(v.data));
alloc_traits::construct(a, vp);
value_destructor<Allocator> on_exit(a, *vp); (void)on_exit;
*p = ::boost::move(*vp);
@@ -154,7 +156,7 @@ struct insert_default_initialized_n_proxy
while (n){
--n;
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *vp = reinterpret_cast<value_type *>(v.data);
value_type *vp = move_detail::force_ptr<value_type *>(v.data);
alloc_traits::construct(a, vp, default_init);
value_destructor<Allocator> on_exit(a, *vp); (void)on_exit;
*p = ::boost::move(*vp);
@@ -295,7 +297,7 @@ struct insert_emplace_proxy
{
BOOST_ASSERT(n ==1); (void)n;
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *vp = reinterpret_cast<value_type *>(v.data);
value_type *vp = move_detail::force_ptr<value_type *>(v.data);
alloc_traits::construct(a, vp, ::boost::forward<Args>(get<IdxPack>(this->args_))...);
BOOST_TRY{
*p = ::boost::move(*vp);
@@ -415,7 +417,7 @@ struct insert_emplace_proxy_arg##N\
{\
BOOST_ASSERT(n == 1); (void)n;\
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
value_type *vp = reinterpret_cast<value_type *>(v.data);\
value_type *vp = move_detail::force_ptr<value_type *>(v.data);\
alloc_traits::construct(a, vp BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\
BOOST_TRY{\
*p = ::boost::move(*vp);\
+9 -8
View File
@@ -46,6 +46,7 @@
#include <boost/move/make_unique.hpp>
#include <boost/move/iterator.hpp>
#include <boost/move/adl_move_swap.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include <boost/move/algo/adaptive_sort.hpp>
#include <boost/move/algo/detail/pdqsort.hpp>
@@ -960,7 +961,7 @@ class flat_tree
std::pair<iterator, bool> emplace_unique(BOOST_FWD_REF(Args)... args)
{
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *pval = reinterpret_cast<value_type *>(v.data);
value_type *pval = move_detail::force_ptr<value_type *>(v.data);
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
stored_allocator_traits::construct(a, pval, ::boost::forward<Args>(args)... );
value_destructor<stored_allocator_type, value_type> d(a, *pval);
@@ -972,7 +973,7 @@ class flat_tree
{
//hint checked in insert_unique
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *pval = reinterpret_cast<value_type *>(v.data);
value_type *pval = move_detail::force_ptr<value_type *>(v.data);
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
stored_allocator_traits::construct(a, pval, ::boost::forward<Args>(args)... );
value_destructor<stored_allocator_type, value_type> d(a, *pval);
@@ -983,7 +984,7 @@ class flat_tree
iterator emplace_equal(BOOST_FWD_REF(Args)... args)
{
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *pval = reinterpret_cast<value_type *>(v.data);
value_type *pval = move_detail::force_ptr<value_type *>(v.data);
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
stored_allocator_traits::construct(a, pval, ::boost::forward<Args>(args)... );
value_destructor<stored_allocator_type, value_type> d(a, *pval);
@@ -995,7 +996,7 @@ class flat_tree
{
//hint checked in insert_equal
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
value_type *pval = reinterpret_cast<value_type *>(v.data);
value_type *pval = move_detail::force_ptr<value_type *>(v.data);
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
stored_allocator_traits::construct(a, pval, ::boost::forward<Args>(args)... );
value_destructor<stored_allocator_type, value_type> d(a, *pval);
@@ -1029,7 +1030,7 @@ class flat_tree
std::pair<iterator, bool> emplace_unique(BOOST_MOVE_UREF##N)\
{\
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
value_type *pval = reinterpret_cast<value_type *>(v.data);\
value_type *pval = move_detail::force_ptr<value_type *>(v.data);\
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
stored_allocator_traits::construct(a, pval BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
value_destructor<stored_allocator_type, value_type> d(a, *pval);\
@@ -1040,7 +1041,7 @@ class flat_tree
iterator emplace_hint_unique(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
value_type *pval = reinterpret_cast<value_type *>(v.data);\
value_type *pval = move_detail::force_ptr<value_type *>(v.data);\
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
stored_allocator_traits::construct(a, pval BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
value_destructor<stored_allocator_type, value_type> d(a, *pval);\
@@ -1051,7 +1052,7 @@ class flat_tree
iterator emplace_equal(BOOST_MOVE_UREF##N)\
{\
typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
value_type *pval = reinterpret_cast<value_type *>(v.data);\
value_type *pval = move_detail::force_ptr<value_type *>(v.data);\
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
stored_allocator_traits::construct(a, pval BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
value_destructor<stored_allocator_type, value_type> d(a, *pval);\
@@ -1062,7 +1063,7 @@ class flat_tree
iterator emplace_hint_equal(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
typename dtl::aligned_storage <sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
value_type *pval = reinterpret_cast<value_type *>(v.data);\
value_type *pval = move_detail::force_ptr<value_type *>(v.data);\
get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
stored_allocator_traits::construct(a, pval BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
value_destructor<stored_allocator_type, value_type> d(a, *pval);\
@@ -26,6 +26,7 @@
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/pool_common.hpp>
#include <boost/move/detail/to_raw_pointer.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/intrusive/pointer_traits.hpp>
@@ -344,7 +345,7 @@ class private_node_pool_impl
//!Returns a reference to the block hook placed in the end of the block
static node_t & get_block_hook (void *block, size_type blocksize)
{
return *reinterpret_cast<node_t*>(reinterpret_cast<char*>(block) + blocksize);
return *move_detail::force_ptr<node_t*>(reinterpret_cast<char*>(block) + blocksize);
}
//!Returns the starting address of the block reference to the block hook placed in the end of the block
+10 -9
View File
@@ -52,6 +52,7 @@
#include <boost/move/detail/fwd_macros.hpp>
#endif
#include <boost/move/detail/move_helpers.hpp>
#include <boost/move/detail/force_ptr.hpp>
// other
#include <boost/core/no_exceptions_support.hpp>
@@ -145,31 +146,31 @@ struct tree_node
# endif
BOOST_CONTAINER_FORCEINLINE T &get_data()
{ return *reinterpret_cast<T*>(this->m_storage.data); }
{ return *move_detail::force_ptr<T*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE const T &get_data() const
{ return *reinterpret_cast<const T*>(this->m_storage.data); }
{ return *move_detail::force_ptr<const T*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE T *get_data_ptr()
{ return reinterpret_cast<T*>(this->m_storage.data); }
{ return move_detail::force_ptr<T*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const
{ return reinterpret_cast<T*>(this->m_storage.data); }
{ return move_detail::force_ptr<T*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data()
{ return *reinterpret_cast<internal_type*>(this->m_storage.data); }
{ return *move_detail::force_ptr<internal_type*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const
{ return *reinterpret_cast<const internal_type*>(this->m_storage.data); }
{ return *move_detail::force_ptr<const internal_type*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr()
{ return reinterpret_cast<internal_type*>(this->m_storage.data); }
{ return move_detail::force_ptr<internal_type*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const
{ return reinterpret_cast<internal_type*>(this->m_storage.data); }
{ return move_detail::force_ptr<internal_type*>(this->m_storage.data); }
BOOST_CONTAINER_FORCEINLINE ~tree_node()
{ reinterpret_cast<internal_type*>(this->m_storage.data)->~internal_type(); }
{ move_detail::force_ptr<internal_type*>(this->m_storage.data)->~internal_type(); }
#if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING)
#pragma GCC diagnostic pop