diff --git a/include/boost/container/detail/advanced_insert_int.hpp b/include/boost/container/detail/advanced_insert_int.hpp index bc6801a..5cc1c1c 100644 --- a/include/boost/container/detail/advanced_insert_int.hpp +++ b/include/boost/container/detail/advanced_insert_int.hpp @@ -39,6 +39,7 @@ #include #include +#include // other #include @@ -138,8 +139,8 @@ struct insert_value_initialized_n_proxy while (n){ --n; storage_t v; - alloc_traits::construct(a, move_detail::force_ptr(&v)); - value_type *vp = move_detail::force_ptr(&v); + alloc_traits::construct(a, (value_type*)&v); + value_type *vp = move_detail::launder_cast(&v); value_destructor on_exit(a, *vp); (void)on_exit; *p = ::boost::move(*vp); ++p; @@ -165,8 +166,8 @@ struct insert_default_initialized_n_proxy while (n){ --n; typename dtl::aligned_storage::value>::type v; - alloc_traits::construct(a, move_detail::force_ptr(&v), default_init); - value_type *vp = move_detail::force_ptr(&v); + alloc_traits::construct(a, (value_type*)&v, default_init); + value_type *vp = move_detail::launder_cast(&v); value_destructor on_exit(a, *vp); (void)on_exit; *p = ::boost::move(*vp); ++p; @@ -312,8 +313,8 @@ struct insert_emplace_proxy { BOOST_ASSERT(n ==1); (void)n; typename dtl::aligned_storage::value>::type v; - alloc_traits::construct(a, move_detail::force_ptr(&v), ::boost::forward(get(this->args_))...); - value_type *vp = move_detail::force_ptr(&v); + alloc_traits::construct(a, (value_type*)&v, ::boost::forward(get(this->args_))...); + value_type *vp = move_detail::launder_cast(&v); BOOST_CONTAINER_TRY{ *p = ::boost::move(*vp); } @@ -435,8 +436,8 @@ struct insert_emplace_proxy_arg##N\ {\ BOOST_ASSERT(n == 1); (void)n;\ typename dtl::aligned_storage::value>::type v;\ - alloc_traits::construct(a, move_detail::force_ptr(&v) BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\ - value_type *vp = move_detail::force_ptr(&v);\ + alloc_traits::construct(a, (value_type*)&v BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\ + value_type *vp = move_detail::launder_cast(&v);\ BOOST_CONTAINER_TRY{\ *p = ::boost::move(*vp);\ }\ diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 5a14826..0fb0e35 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -975,8 +976,8 @@ class flat_tree { typename dtl::aligned_storage::value>::type v; get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); - stored_allocator_traits::construct(a, move_detail::force_ptr(&v), ::boost::forward(args)... ); - value_type *pval = move_detail::force_ptr(&v); + stored_allocator_traits::construct(a, (value_type *)(&v), ::boost::forward(args)... ); + value_type *pval = move_detail::launder_cast(&v); value_destructor d(a, *pval); return this->insert_unique(::boost::move(*pval)); } @@ -987,8 +988,8 @@ class flat_tree //hint checked in insert_unique typename dtl::aligned_storage::value>::type v; get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); - stored_allocator_traits::construct(a, move_detail::force_ptr(&v), ::boost::forward(args)... ); - value_type *pval = move_detail::force_ptr(&v); + stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward(args)... ); + value_type *pval = move_detail::launder_cast(&v); value_destructor d(a, *pval); return this->insert_unique(hint, ::boost::move(*pval)); } @@ -998,8 +999,8 @@ class flat_tree { typename dtl::aligned_storage::value>::type v; get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); - stored_allocator_traits::construct(a, move_detail::force_ptr(&v), ::boost::forward(args)... ); - value_type *pval = move_detail::force_ptr(&v); + stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward(args)... ); + value_type *pval = move_detail::launder_cast(&v); value_destructor d(a, *pval); return this->insert_equal(::boost::move(*pval)); } @@ -1010,8 +1011,8 @@ class flat_tree //hint checked in insert_equal typename dtl::aligned_storage::value>::type v; get_stored_allocator_noconst_return_t a = this->get_stored_allocator(); - stored_allocator_traits::construct(a, move_detail::force_ptr(&v), ::boost::forward(args)... ); - value_type *pval = move_detail::force_ptr(&v); + stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward(args)... ); + value_type *pval = move_detail::launder_cast(&v); value_destructor d(a, *pval); return this->insert_equal(hint, ::boost::move(*pval)); } @@ -1044,8 +1045,8 @@ class flat_tree {\ typename dtl::aligned_storage::value>::type v;\ get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\ - stored_allocator_traits::construct(a, move_detail::force_ptr(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ - value_type *pval = move_detail::force_ptr(&v);\ + stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ + value_type *pval = move_detail::launder_cast(&v);\ value_destructor d(a, *pval);\ return this->insert_unique(::boost::move(*pval));\ }\ @@ -1055,8 +1056,8 @@ class flat_tree {\ typename dtl::aligned_storage::value>::type v;\ get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\ - stored_allocator_traits::construct(a, move_detail::force_ptr(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ - value_type *pval = move_detail::force_ptr(&v);\ + stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ + value_type *pval = move_detail::launder_cast(&v);\ value_destructor d(a, *pval);\ return this->insert_unique(hint, ::boost::move(*pval));\ }\ @@ -1066,8 +1067,8 @@ class flat_tree {\ typename dtl::aligned_storage::value>::type v;\ get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\ - stored_allocator_traits::construct(a, move_detail::force_ptr(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ - value_type *pval = move_detail::force_ptr(&v);\ + stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ + value_type *pval = move_detail::launder_cast(&v);\ value_destructor d(a, *pval);\ return this->insert_equal(::boost::move(*pval));\ }\ @@ -1077,8 +1078,8 @@ class flat_tree {\ typename dtl::aligned_storage ::value>::type v;\ get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\ - stored_allocator_traits::construct(a, move_detail::force_ptr(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ - value_type *pval = move_detail::force_ptr(&v);\ + stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ + value_type *pval = move_detail::launder_cast(&v);\ value_destructor d(a, *pval);\ return this->insert_equal(hint, ::boost::move(*pval));\ }\ diff --git a/include/boost/container/detail/node_alloc_holder.hpp b/include/boost/container/detail/node_alloc_holder.hpp index 1ebf21a..9343cb6 100644 --- a/include/boost/container/detail/node_alloc_holder.hpp +++ b/include/boost/container/detail/node_alloc_holder.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -119,16 +120,16 @@ struct base_node } inline T &get_data() - { return *move_detail::force_ptr(this->m_storage.data); } + { return *move_detail::force_ptr(&this->m_storage); } inline const T &get_data() const - { return *move_detail::force_ptr(this->m_storage.data); } + { return *move_detail::launder_cast(&this->m_storage); } inline internal_type &get_real_data() - { return *move_detail::force_ptr(this->m_storage.data); } + { return *move_detail::launder_cast(&this->m_storage); } inline const internal_type &get_real_data() const - { return *move_detail::force_ptr(this->m_storage.data); } + { return *move_detail::launder_cast(&this->m_storage); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index f4a27b2..b5430fe 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -52,7 +52,6 @@ #include #endif #include -#include diff --git a/include/boost/container/devector.hpp b/include/boost/container/devector.hpp index 5195fa0..27e11f0 100644 --- a/include/boost/container/devector.hpp +++ b/include/boost/container/devector.hpp @@ -46,7 +46,6 @@ #include #include #include -#include //std #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index 04512c5..117e275 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -43,7 +43,6 @@ # include #endif #include -#include // intrusive #include diff --git a/include/boost/container/node_handle.hpp b/include/boost/container/node_handle.hpp index 41bea97..4b6e021 100644 --- a/include/boost/container/node_handle.hpp +++ b/include/boost/container/node_handle.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,7 @@ class node_handle } void destroy_alloc() BOOST_NOEXCEPT - { static_cast((void*)m_nalloc_storage.data)->~nallocator_type(); } + { move_detail::launder_cast(&m_nalloc_storage)->~nallocator_type(); } node_pointer &get_node_pointer() BOOST_NOEXCEPT { return m_ptr; } @@ -381,7 +382,7 @@ class node_handle nallocator_type &node_alloc() BOOST_NOEXCEPT { BOOST_ASSERT(!empty()); - return *static_cast((void*)m_nalloc_storage.data); + return *move_detail::launder_cast(&m_nalloc_storage); } @@ -391,7 +392,7 @@ class node_handle const nallocator_type &node_alloc() const BOOST_NOEXCEPT { BOOST_ASSERT(!empty()); - return *static_cast((const void*)m_nalloc_storage.data); + return *move_detail::launder_cast(&m_nalloc_storage); } //! Effects: x.swap(y). diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index 5aa4193..a863d1a 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -47,7 +47,7 @@ #include #endif #include -#include + // std #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) #include diff --git a/include/boost/container/small_vector.hpp b/include/boost/container/small_vector.hpp index 28adc46..086b30a 100644 --- a/include/boost/container/small_vector.hpp +++ b/include/boost/container/small_vector.hpp @@ -39,7 +39,6 @@ #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include #endif -#include //std #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) @@ -488,7 +487,7 @@ template inline typename small_vector_allocator::const_pointer small_vector_allocator::internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW { - const vector_type& v = reinterpret_cast(*this); + const vector_type& v = *static_cast(static_cast(this)); BOOST_ASSERT((std::size_t(this) % dtl::alignment_of< small_vector_storage_offset >::value) == 0); const char *addr = reinterpret_cast(&v); typedef typename boost::intrusive::pointer_traits::template rebind_pointer::type const_char_pointer; @@ -501,7 +500,7 @@ template inline typename small_vector_allocator::pointer small_vector_allocator::internal_storage() BOOST_NOEXCEPT_OR_NOTHROW { - vector_type& v = reinterpret_cast(*this); + vector_type& v = *static_cast(static_cast(this)); BOOST_ASSERT((std::size_t(this) % dtl::alignment_of< small_vector_storage_offset >::value) == 0); char* addr = reinterpret_cast(&v); typedef typename boost::intrusive::pointer_traits::template rebind_pointer::type char_pointer; diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 0ab37b9..6718122 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include // move/detail #include #include @@ -166,19 +166,19 @@ struct node # endif inline T &get_data() - { return *boost::move_detail::force_ptr(this->m_storage.data); } + { return *boost::move_detail::launder_cast(&this->m_storage); } inline const T &get_data() const - { return *boost::move_detail::force_ptr(this->m_storage.data); } + { return *boost::move_detail::launder_cast(&this->m_storage); } inline T *get_data_ptr() - { return boost::move_detail::force_ptr(this->m_storage.data); } + { return boost::move_detail::launder_cast(&this->m_storage); } inline const T *get_data_ptr() const - { return boost::move_detail::force_ptr(this->m_storage.data); } + { return boost::move_detail::launder_cast(&this->m_storage); } inline ~node() - { boost::move_detail::force_ptr(this->m_storage.data)->~T(); } + { boost::move_detail::launder_cast(&this->m_storage)->~T(); } #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING) #pragma GCC diagnostic pop diff --git a/include/boost/container/static_vector.hpp b/include/boost/container/static_vector.hpp index 88bf2ba..3d2bada 100644 --- a/include/boost/container/static_vector.hpp +++ b/include/boost/container/static_vector.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -63,10 +64,7 @@ class static_storage_allocator { return *this; } inline T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW - { return const_cast(static_cast(static_cast(storage.data))); } - - inline T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW - { return static_cast(static_cast(storage.data)); } + { return move_detail::launder_cast(&storage); } static const std::size_t internal_capacity = N; diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 28b4bb5..e7cfc23 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -43,7 +43,7 @@ //intrusive #include #include -#include +#include //move #include #include @@ -226,7 +226,7 @@ class basic_string_base { inline void init() { - short_t &s = *::new(this->m_repr.data) short_t; + short_t &s = *::new(&this->m_repr) short_t; s.h.is_short = 1; s.h.length = 0; } @@ -241,16 +241,16 @@ class basic_string_base { this->init(); } inline const short_t *pshort_repr() const - { return move_detail::force_ptr(m_repr.data); } + { return move_detail::launder_cast(&m_repr); } inline const long_t *plong_repr() const - { return move_detail::force_ptr(m_repr.data); } + { return move_detail::launder_cast(&m_repr); } inline short_t *pshort_repr() - { return move_detail::force_ptr(m_repr.data); } + { return move_detail::launder_cast(&m_repr); } inline long_t *plong_repr() - { return move_detail::force_ptr(m_repr.data); } + { return move_detail::launder_cast(&m_repr); } repr_t m_repr; } members_; @@ -280,7 +280,7 @@ class basic_string_base inline short_t *construct_short() { - short_t *ps = ::new(this->members_.m_repr.data) short_t; + short_t *ps = ::new(&this->members_.m_repr) short_t; ps->h.is_short = 1; return ps; } @@ -302,7 +302,7 @@ class basic_string_base inline long_t *construct_long() { - long_t *pl = ::new(this->members_.m_repr.data) long_t; + long_t *pl = ::new(&this->members_.m_repr) long_t; //is_short flag is written in the constructor return pl; } diff --git a/test/allocator_argument_tester.hpp b/test/allocator_argument_tester.hpp index 16b19bc..584d2b7 100644 --- a/test/allocator_argument_tester.hpp +++ b/test/allocator_argument_tester.hpp @@ -14,7 +14,6 @@ #include #include #include -#include template class propagation_test_allocator @@ -69,11 +68,18 @@ class propagation_test_allocator std::size_t max_size() const { return std::size_t(-1); } - T* allocate(std::size_t n) - { return boost::move_detail::force_ptr(::new char[n*sizeof(T)]); } + value_type* allocate(std::size_t count) + { return static_cast(::operator new(count * sizeof(value_type))); } - void deallocate(T*p, std::size_t) - { delete []static_cast(static_cast(p)); } + void deallocate(value_type *ptr, std::size_t n) + { + (void)n; + # if __cpp_sized_deallocation + ::operator delete((void*)ptr, n * sizeof(value_type)); + #else + ::operator delete((void*)ptr); + # endif + } bool m_move_contructed; bool m_move_assigned; diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index 2fd2aa8..8688647 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -61,10 +60,17 @@ class simple_allocator {} T* allocate(std::size_t n) - { return move_detail::force_ptr(::new char[sizeof(T)*n]); } + { return (T*) ::operator new(sizeof(T) * n); } - void deallocate(T*p, std::size_t) - { delete[] ((char*)p);} + void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW + { + (void)n; + # if __cpp_sized_deallocation + ::operator delete((void*)ptr, n * sizeof(T)); + #else + ::operator delete((void*)ptr); + # endif + } friend bool operator==(const simple_allocator &, const simple_allocator &) { return true; } @@ -176,10 +182,17 @@ class propagation_test_allocator { unique_id_ = id; } T* allocate(std::size_t n) - { return move_detail::force_ptr(::new char[sizeof(T)*n]); } + { return static_cast(::operator new(n * sizeof(T))); } - void deallocate(T*p, std::size_t) - { delete[] ((char*)p);} + void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW + { + (void)n; + # if __cpp_sized_deallocation + ::operator delete((void*)ptr, n * sizeof(T)); + #else + ::operator delete((void*)ptr); + # endif + } friend bool operator==(const propagation_test_allocator &a, const propagation_test_allocator &b) { return EqualIfEqualIds ? a.id_ == b.id_ : true; } diff --git a/test/emplace_test.hpp b/test/emplace_test.hpp index d756579..8daf6a4 100644 --- a/test/emplace_test.hpp +++ b/test/emplace_test.hpp @@ -17,7 +17,7 @@ #include #include #include -#include //adl_move_swap +#include //adl_move_swap namespace boost{ namespace container { @@ -152,7 +152,7 @@ static boost::container::dtl::aligned_storage::type p static EmplaceIntPair* initialize_emplace_int_pair() { - EmplaceIntPair* ret = move_detail::force_ptr(&pair_storage); + EmplaceIntPair* ret = move_detail::launder_cast(&pair_storage); for(unsigned int i = 0; i != 10; ++i){ new(&ret->first)EmplaceInt(); new(&ret->second)EmplaceInt(); diff --git a/test/explicit_inst_vector_test.cpp b/test/explicit_inst_vector_test.cpp index 9141319..fadb651 100644 --- a/test/explicit_inst_vector_test.cpp +++ b/test/explicit_inst_vector_test.cpp @@ -22,7 +22,6 @@ volatile ::boost::container::vector dummy; #include #include "movable_int.hpp" #include "dummy_test_allocator.hpp" -#include class CustomAllocator { @@ -34,10 +33,17 @@ class CustomAllocator typedef short difference_type; pointer allocate(size_type count) - { return boost::move_detail::force_ptr(new char[sizeof(value_type)*count]); } + { return static_cast(::operator new(count * sizeof(value_type))); } - void deallocate(pointer ptr, size_type ) - { delete [](char*)ptr; } + void deallocate(pointer ptr, size_type n) + { + (void)n; + # if __cpp_sized_deallocation + ::operator delete((void*)ptr, n * sizeof(value_type)); + #else + ::operator delete((void*)ptr); + # endif + } friend bool operator==(CustomAllocator const&, CustomAllocator const&) BOOST_NOEXCEPT { return true; } diff --git a/test/static_vector_test.cpp b/test/static_vector_test.cpp index a296e97..1fa1ea6 100644 --- a/test/static_vector_test.cpp +++ b/test/static_vector_test.cpp @@ -630,7 +630,7 @@ bool default_init_test()//Test for default initialization typedef static_vector di_vector_t; { - typename dtl::aligned_storage::type as; + dtl::aligned_storage::type as; di_vector_t *pv = ::new(as.data)di_vector_t(Capacity); //Use volatile pointer to make compiler's job harder, as we are riding on UB