From 3f76f9fdf7b8ffada736c47960d115d95e82bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 28 Dec 2021 15:17:15 +0100 Subject: [PATCH] Fixes #206 ("operator-> on static_vector::iterator causes cast alignment warning") --- bench/detail/varray.hpp | 6 ++++-- doc/container.qbk | 8 ++++++++ include/boost/container/adaptive_pool.hpp | 18 ++++++++++++------ include/boost/container/allocator.hpp | 11 ++++++++--- .../detail/adaptive_node_pool_impl.hpp | 9 +++++---- include/boost/container/detail/addressof.hpp | 12 ++---------- .../container/detail/advanced_insert_int.hpp | 10 ++++++---- include/boost/container/detail/flat_tree.hpp | 17 +++++++++-------- .../boost/container/detail/node_pool_impl.hpp | 3 ++- include/boost/container/detail/tree.hpp | 19 ++++++++++--------- include/boost/container/devector.hpp | 5 +++-- include/boost/container/flat_map.hpp | 5 +++-- include/boost/container/list.hpp | 19 ++++++++++--------- include/boost/container/slist.hpp | 19 ++++++++++--------- include/boost/container/small_vector.hpp | 5 +++-- include/boost/container/stable_vector.hpp | 11 ++++++----- include/boost/container/string.hpp | 17 +++++++++-------- test/allocator_argument_tester.hpp | 3 ++- test/default_init_test.hpp | 3 ++- test/dummy_test_allocator.hpp | 6 +++--- test/emplace_test.hpp | 3 ++- test/expand_bwd_test_template.hpp | 5 +++-- test/explicit_inst_vector_test.cpp | 3 ++- 23 files changed, 124 insertions(+), 93 deletions(-) diff --git a/bench/detail/varray.hpp b/bench/detail/varray.hpp index a34158e..9189e1b 100644 --- a/bench/detail/varray.hpp +++ b/bench/detail/varray.hpp @@ -33,6 +33,8 @@ #include #include //adl_move_swap +#include //adl_move_swap + #include "varray_util.hpp" @@ -2105,12 +2107,12 @@ private: pointer ptr() { - return pointer(reinterpret_cast(this)); + return pointer(move_detail::force_ptr(this)); } const_pointer ptr() const { - return const_pointer(reinterpret_cast(this)); + return const_pointer(move_detail::force_ptr(this)); } }; diff --git a/doc/container.qbk b/doc/container.qbk index 1c2fd8f..ca788fd 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1338,6 +1338,14 @@ use [*Boost.Container]? There are several reasons for that: [section:release_notes Release Notes] +[section:release_notes_boost_1_79_00 Boost 1.79 Release] + +* The library now compiles without warnings with GCC's -Wcast-align=strict +* Fixed bugs/issues: + * [@https://github.com/boostorg/container/issues/206 GitHub #206: ['"operator-> on static_vector::iterator causes cast alignment warning"]]. + +[endsect] + [section:release_notes_boost_1_78_00 Boost 1.78 Release] * Fixed bugs/issues: diff --git a/include/boost/container/adaptive_pool.hpp b/include/boost/container/adaptive_pool.hpp index 76c620f..fb0e24b 100644 --- a/include/boost/container/adaptive_pool.hpp +++ b/include/boost/container/adaptive_pool.hpp @@ -31,6 +31,8 @@ #include #include +#include + #include #include #include @@ -263,7 +265,8 @@ class adaptive_pool ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) );*/ if(BOOST_UNLIKELY(!dlmalloc_multialloc_nodes - (n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain)))){ + ( n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain)))){ boost::container::throw_bad_alloc(); } } @@ -283,7 +286,8 @@ class adaptive_pool ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) );*/ if(BOOST_UNLIKELY(!dlmalloc_multialloc_arrays - (n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain)))){ + ( n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain)))){ boost::container::throw_bad_alloc(); } } @@ -295,7 +299,7 @@ class adaptive_pool size_t size(chain.size()); BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&ch, beg, last, size); dlmalloc_multidealloc(&ch);*/ - dlmalloc_multidealloc(reinterpret_cast(&chain)); + dlmalloc_multidealloc(move_detail::force_ptr(&chain)); } //!Deallocates all free blocks of the pool @@ -544,7 +548,8 @@ class private_adaptive_pool { BOOST_STATIC_ASSERT(( Version > 1 )); if(BOOST_UNLIKELY(!dlmalloc_multialloc_nodes - (n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain)))){ + ( n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain)))){ boost::container::throw_bad_alloc(); } } @@ -555,14 +560,15 @@ class private_adaptive_pool { BOOST_STATIC_ASSERT(( Version > 1 )); if(BOOST_UNLIKELY(!dlmalloc_multialloc_arrays - (n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain)))){ + (n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain)))){ boost::container::throw_bad_alloc(); } } void deallocate_many(multiallocation_chain &chain) BOOST_NOEXCEPT_OR_NOTHROW { - dlmalloc_multidealloc(reinterpret_cast(&chain)); + dlmalloc_multidealloc(move_detail::force_ptr(&chain)); } //!Deallocates all free blocks of the pool diff --git a/include/boost/container/allocator.hpp b/include/boost/container/allocator.hpp index 8489f48..418407e 100644 --- a/include/boost/container/allocator.hpp +++ b/include/boost/container/allocator.hpp @@ -27,6 +27,9 @@ #include #include #include + +#include + #include #include @@ -298,7 +301,8 @@ class allocator ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) ); /* - if(!dlmalloc_multialloc_nodes(n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain))){ + if(!dlmalloc_multialloc_nodes( n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain))){ boost::container::throw_bad_alloc(); }*/ } @@ -319,7 +323,8 @@ class allocator ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) ); /* - if(!dlmalloc_multialloc_arrays(n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast(&chain))){ + if(!dlmalloc_multialloc_arrays( n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS + , move_detail::force_ptr(&chain))){ boost::container::throw_bad_alloc(); }*/ } @@ -335,7 +340,7 @@ class allocator size_t size(chain.size()); BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&ch, beg, last, size); dlmalloc_multidealloc(&ch); - //dlmalloc_multidealloc(reinterpret_cast(&chain)); + //dlmalloc_multidealloc(move_detail::force_ptr(&chain)); } private: diff --git a/include/boost/container/detail/adaptive_node_pool_impl.hpp b/include/boost/container/detail/adaptive_node_pool_impl.hpp index 9d96084..5342909 100644 --- a/include/boost/container/detail/adaptive_node_pool_impl.hpp +++ b/include/boost/container/detail/adaptive_node_pool_impl.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include // intrusive #include @@ -540,7 +541,7 @@ class private_adaptive_node_pool_impl_common BOOST_ASSERT(hdr_off_holder->hdr_offset == offset); BOOST_ASSERT(0 == (reinterpret_cast(hdr_off_holder) & (real_block_alignment - 1))); BOOST_ASSERT(0 == (hdr_off_holder->hdr_offset & (real_block_alignment - 1))); - hdr_off_holder = reinterpret_cast(reinterpret_cast(hdr_off_holder) + real_block_alignment); + hdr_off_holder = move_detail::force_ptr(reinterpret_cast(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 *const hdr_off_holder = move_detail::force_ptr (reinterpret_cast(block) - (num_subblocks-1)*real_block_alignment); BOOST_ASSERT(hdr_off_holder->hdr_offset == size_type(reinterpret_cast(block) - reinterpret_cast(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(block); + return move_detail::force_ptr(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((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 = move_detail::force_ptr (reinterpret_cast(hdr_off_holder) + hdr_off_holder->hdr_offset); BOOST_ASSERT(block->hdr_offset == 0); return block; diff --git a/include/boost/container/detail/addressof.hpp b/include/boost/container/detail/addressof.hpp index b3b8a4d..00679b8 100644 --- a/include/boost/container/detail/addressof.hpp +++ b/include/boost/container/detail/addressof.hpp @@ -18,21 +18,13 @@ # pragma once #endif -#include +#include namespace boost { namespace container { namespace dtl { -template -BOOST_CONTAINER_FORCEINLINE T* addressof(T& obj) -{ - return static_cast( - static_cast( - const_cast( - &reinterpret_cast(obj) - ))); -} +using boost::move_detail::addressof; } //namespace dtl { } //namespace container { diff --git a/include/boost/container/detail/advanced_insert_int.hpp b/include/boost/container/detail/advanced_insert_int.hpp index ea03685..fef1303 100644 --- a/include/boost/container/detail/advanced_insert_int.hpp +++ b/include/boost/container/detail/advanced_insert_int.hpp @@ -36,7 +36,9 @@ #include #endif // move + #include +#include // other #include #include @@ -129,7 +131,7 @@ struct insert_value_initialized_n_proxy while (n){ --n; storage_t v; - value_type *vp = reinterpret_cast(v.data); + value_type *vp = move_detail::force_ptr(static_cast(v.data)); alloc_traits::construct(a, vp); value_destructor 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::value>::type v; - value_type *vp = reinterpret_cast(v.data); + value_type *vp = move_detail::force_ptr(v.data); alloc_traits::construct(a, vp, default_init); value_destructor 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::value>::type v; - value_type *vp = reinterpret_cast(v.data); + value_type *vp = move_detail::force_ptr(v.data); alloc_traits::construct(a, vp, ::boost::forward(get(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::value>::type v;\ - value_type *vp = reinterpret_cast(v.data);\ + value_type *vp = move_detail::force_ptr(v.data);\ alloc_traits::construct(a, vp BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\ BOOST_TRY{\ *p = ::boost::move(*vp);\ diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 7311d9f..4fa729a 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -960,7 +961,7 @@ class flat_tree std::pair emplace_unique(BOOST_FWD_REF(Args)... args) { typename dtl::aligned_storage::value>::type v; - value_type *pval = reinterpret_cast(v.data); + value_type *pval = move_detail::force_ptr(v.data); get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); stored_allocator_traits::construct(a, pval, ::boost::forward(args)... ); value_destructor d(a, *pval); @@ -972,7 +973,7 @@ class flat_tree { //hint checked in insert_unique typename dtl::aligned_storage::value>::type v; - value_type *pval = reinterpret_cast(v.data); + value_type *pval = move_detail::force_ptr(v.data); get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); stored_allocator_traits::construct(a, pval, ::boost::forward(args)... ); value_destructor d(a, *pval); @@ -983,7 +984,7 @@ class flat_tree iterator emplace_equal(BOOST_FWD_REF(Args)... args) { typename dtl::aligned_storage::value>::type v; - value_type *pval = reinterpret_cast(v.data); + value_type *pval = move_detail::force_ptr(v.data); get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); stored_allocator_traits::construct(a, pval, ::boost::forward(args)... ); value_destructor d(a, *pval); @@ -995,7 +996,7 @@ class flat_tree { //hint checked in insert_equal typename dtl::aligned_storage::value>::type v; - value_type *pval = reinterpret_cast(v.data); + value_type *pval = move_detail::force_ptr(v.data); get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); stored_allocator_traits::construct(a, pval, ::boost::forward(args)... ); value_destructor d(a, *pval); @@ -1029,7 +1030,7 @@ class flat_tree std::pair emplace_unique(BOOST_MOVE_UREF##N)\ {\ typename dtl::aligned_storage::value>::type v;\ - value_type *pval = reinterpret_cast(v.data);\ + value_type *pval = move_detail::force_ptr(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 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::value>::type v;\ - value_type *pval = reinterpret_cast(v.data);\ + value_type *pval = move_detail::force_ptr(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 d(a, *pval);\ @@ -1051,7 +1052,7 @@ class flat_tree iterator emplace_equal(BOOST_MOVE_UREF##N)\ {\ typename dtl::aligned_storage::value>::type v;\ - value_type *pval = reinterpret_cast(v.data);\ + value_type *pval = move_detail::force_ptr(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 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 ::value>::type v;\ - value_type *pval = reinterpret_cast(v.data);\ + value_type *pval = move_detail::force_ptr(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 d(a, *pval);\ diff --git a/include/boost/container/detail/node_pool_impl.hpp b/include/boost/container/detail/node_pool_impl.hpp index 97f555b..1751e00 100644 --- a/include/boost/container/detail/node_pool_impl.hpp +++ b/include/boost/container/detail/node_pool_impl.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -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(reinterpret_cast(block) + blocksize); + return *move_detail::force_ptr(reinterpret_cast(block) + blocksize); } //!Returns the starting address of the block reference to the block hook placed in the end of the block diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index 3566e81..ac72e57 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -52,6 +52,7 @@ #include #endif #include +#include // other #include @@ -145,31 +146,31 @@ struct tree_node # endif BOOST_CONTAINER_FORCEINLINE T &get_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T &get_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE T *get_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE ~tree_node() - { reinterpret_cast(this->m_storage.data)->~internal_type(); } + { move_detail::force_ptr(this->m_storage.data)->~internal_type(); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/devector.hpp b/include/boost/container/devector.hpp index 10a4088..e201fe1 100644 --- a/include/boost/container/devector.hpp +++ b/include/boost/container/devector.hpp @@ -47,6 +47,7 @@ #include #include #include +#include #include @@ -2549,7 +2550,7 @@ class devector {\ BOOST_ASSERT(size() >= 1);\ typename dtl::aligned_storage::value>::type v;\ - T *vp = reinterpret_cast(v.data);\ + T *vp = move_detail::force_ptr(v.data);\ allocator_traits_type::construct(get_stored_allocator(), vp BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ T &tmp = *vp;\ dtl::value_destructor on_exit(get_stored_allocator(), tmp); (void)on_exit;\ @@ -2564,7 +2565,7 @@ class devector else if (back_free_capacity()) {\ BOOST_ASSERT(size() >= 1);\ typename dtl::aligned_storage::value>::type v;\ - T *vp = reinterpret_cast(v.data);\ + T *vp = move_detail::force_ptr(v.data);\ allocator_traits_type::construct(get_stored_allocator(), vp BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ T &tmp = *vp;\ dtl::value_destructor on_exit(get_stored_allocator(), tmp); (void)on_exit;\ diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index 00b0350..49e275d 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -39,6 +39,7 @@ #include #endif #include +#include // intrusive #include //pair #include //less, equal @@ -61,12 +62,12 @@ namespace dtl{ template BOOST_CONTAINER_FORCEINLINE static D &force(S &s) -{ return *reinterpret_cast(&s); } +{ return *move_detail::force_ptr(&s); } template BOOST_CONTAINER_FORCEINLINE static D force_copy(const S &s) { - const D *const vp = reinterpret_cast(&s); + const D *const vp = move_detail::force_ptr(&s); D ret_val(*vp); return ret_val; } diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index cbc1fb8..cb680a6 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -43,6 +43,7 @@ # include #endif #include +#include // intrusive #include @@ -86,31 +87,31 @@ struct list_node # endif BOOST_CONTAINER_FORCEINLINE T &get_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T &get_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE T *get_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE ~list_node() - { reinterpret_cast(this->m_storage.data)->~T(); } + { move_detail::force_ptr(this->m_storage.data)->~T(); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index 3e3449a..9e92de1 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -47,6 +47,7 @@ #include #endif #include +#include // other #include // std @@ -91,31 +92,31 @@ struct slist_node # endif BOOST_CONTAINER_FORCEINLINE T &get_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T &get_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE T *get_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE ~slist_node() - { reinterpret_cast(this->m_storage.data)->~T(); } + { move_detail::force_ptr(this->m_storage.data)->~T(); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/small_vector.hpp b/include/boost/container/small_vector.hpp index 1f22eaa..088d51d 100644 --- a/include/boost/container/small_vector.hpp +++ b/include/boost/container/small_vector.hpp @@ -39,6 +39,7 @@ #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include #endif +#include //std #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) @@ -324,7 +325,7 @@ class small_vector_allocator const_pointer internal_storage() const { const vector_alloc_holder_t &v_holder = static_cast(*this); - const vector_base &v_base = reinterpret_cast(v_holder); + const vector_base &v_base = *move_detail::force_ptr(&v_holder); const derived_type &d_base = static_cast(v_base); return d_base.internal_storage(); } @@ -333,7 +334,7 @@ class small_vector_allocator pointer internal_storage() { vector_alloc_holder_t &v_holder = static_cast(*this); - vector_base &v_base = reinterpret_cast(v_holder); + vector_base &v_base = *move_detail::force_ptr(&v_holder); derived_type &d_base = static_cast(v_base); return d_base.internal_storage(); } diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 8019b2e..0c93f98 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -54,6 +54,7 @@ #include #include #include +#include // move/detail #include // other @@ -165,19 +166,19 @@ struct node # endif BOOST_CONTAINER_FORCEINLINE T &get_data() - { return *reinterpret_cast(this->m_storage.data); } + { return *boost::move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T &get_data() const - { return *reinterpret_cast(this->m_storage.data); } + { return *boost::move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE T *get_data_ptr() - { return reinterpret_cast(this->m_storage.data); } + { return boost::move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const - { return reinterpret_cast(this->m_storage.data); } + { return boost::move_detail::force_ptr(this->m_storage.data); } BOOST_CONTAINER_FORCEINLINE ~node() - { reinterpret_cast(this->m_storage.data)->~T(); } + { boost::move_detail::force_ptr(this->m_storage.data)->~T(); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 32e83fa..9630099 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -39,18 +39,19 @@ #include #include #include - +#include // for char_traits +//intrusive #include - +#include +#include +//move #include #include #include #include #include -#include -#include // for char_traits #include #include // #include @@ -227,16 +228,16 @@ class basic_string_base { this->init(); } BOOST_CONTAINER_FORCEINLINE const short_t *pshort_repr() const - { return reinterpret_cast(m_repr.data); } + { return move_detail::force_ptr(m_repr.data); } BOOST_CONTAINER_FORCEINLINE const long_t *plong_repr() const - { return reinterpret_cast(m_repr.data); } + { return move_detail::force_ptr(m_repr.data); } BOOST_CONTAINER_FORCEINLINE short_t *pshort_repr() - { return reinterpret_cast(m_repr.data); } + { return move_detail::force_ptr(m_repr.data); } BOOST_CONTAINER_FORCEINLINE long_t *plong_repr() - { return reinterpret_cast(m_repr.data); } + { return move_detail::force_ptr(m_repr.data); } repr_t m_repr; } members_; diff --git a/test/allocator_argument_tester.hpp b/test/allocator_argument_tester.hpp index 7399328..f3ef0b6 100644 --- a/test/allocator_argument_tester.hpp +++ b/test/allocator_argument_tester.hpp @@ -14,6 +14,7 @@ #include #include #include +#include template class propagation_test_allocator @@ -69,7 +70,7 @@ class propagation_test_allocator { return std::size_t(-1); } T* allocate(std::size_t n) - { return (T*)::new char[n*sizeof(T)]; } + { return boost::move_detail::force_ptr(::new char[n*sizeof(T)]); } void deallocate(T*p, std::size_t) { delete []static_cast(static_cast(p)); } diff --git a/test/default_init_test.hpp b/test/default_init_test.hpp index 7d6bedc..b169603 100644 --- a/test/default_init_test.hpp +++ b/test/default_init_test.hpp @@ -13,6 +13,7 @@ #include #include +#include #include @@ -77,7 +78,7 @@ class default_init_allocator puc_raw[i] = static_cast(s_pattern--); } } - return (Integral*)puc_raw;; + return move_detail::force_ptr(puc_raw); } void deallocate(Integral *p, std::size_t) diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index 1c621ae..2fd2aa8 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -34,7 +34,7 @@ #include #include - +#include #include #include @@ -61,7 +61,7 @@ class simple_allocator {} T* allocate(std::size_t n) - { return (T*)::new char[sizeof(T)*n]; } + { return move_detail::force_ptr(::new char[sizeof(T)*n]); } void deallocate(T*p, std::size_t) { delete[] ((char*)p);} @@ -176,7 +176,7 @@ class propagation_test_allocator { unique_id_ = id; } T* allocate(std::size_t n) - { return (T*)::new char[sizeof(T)*n]; } + { return move_detail::force_ptr(::new char[sizeof(T)*n]); } void deallocate(T*p, std::size_t) { delete[] ((char*)p);} diff --git a/test/emplace_test.hpp b/test/emplace_test.hpp index f017d95..d756579 100644 --- a/test/emplace_test.hpp +++ b/test/emplace_test.hpp @@ -17,6 +17,7 @@ #include #include #include +#include //adl_move_swap namespace boost{ namespace container { @@ -151,7 +152,7 @@ static boost::container::dtl::aligned_storage::type p static EmplaceIntPair* initialize_emplace_int_pair() { - EmplaceIntPair* ret = reinterpret_cast(&pair_storage); + EmplaceIntPair* ret = move_detail::force_ptr(&pair_storage); for(unsigned int i = 0; i != 10; ++i){ new(&ret->first)EmplaceInt(); new(&ret->second)EmplaceInt(); diff --git a/test/expand_bwd_test_template.hpp b/test/expand_bwd_test_template.hpp index 381a5e2..e86a413 100644 --- a/test/expand_bwd_test_template.hpp +++ b/test/expand_bwd_test_template.hpp @@ -19,6 +19,7 @@ #include //equal() #include "movable_int.hpp" #include +#include namespace boost { namespace container { namespace test { @@ -85,7 +86,7 @@ bool test_insert_with_expand_bwd() { boost::movelib::unique_ptr memptr = boost::movelib::make_unique_definit(MemorySize*sizeof(value_type)); - value_type *memory = (value_type*)memptr.get(); + value_type *memory = move_detail::force_ptr(memptr.get()); std::vector initial_data; initial_data.resize(InitialSize[iteration]); for(unsigned int i = 0; i < InitialSize[iteration]; ++i){ @@ -148,7 +149,7 @@ bool test_assign_with_expand_bwd() { boost::movelib::unique_ptr memptr = boost::movelib::make_unique_definit(MemorySize*sizeof(value_type)); - value_type *memory = (value_type*)memptr.get(); + value_type *memory = move_detail::force_ptr(memptr.get()); //Create initial data std::vector initial_data; initial_data.resize(InitialSize[iteration]); diff --git a/test/explicit_inst_vector_test.cpp b/test/explicit_inst_vector_test.cpp index 6d2a2cc..9141319 100644 --- a/test/explicit_inst_vector_test.cpp +++ b/test/explicit_inst_vector_test.cpp @@ -22,6 +22,7 @@ volatile ::boost::container::vector dummy; #include #include "movable_int.hpp" #include "dummy_test_allocator.hpp" +#include class CustomAllocator { @@ -33,7 +34,7 @@ class CustomAllocator typedef short difference_type; pointer allocate(size_type count) - { return (pointer)new char[sizeof(value_type)*count]; } + { return boost::move_detail::force_ptr(new char[sizeof(value_type)*count]); } void deallocate(pointer ptr, size_type ) { delete [](char*)ptr; }