From 03abe8c02c17e4b9876b006174375a927a1cb2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 15 Apr 2024 12:51:44 +0200 Subject: [PATCH] Return start() pointer by value to limit aliasing --- bench/detail/varray.hpp | 15 ++++++++------- include/boost/container/vector.hpp | 9 ++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bench/detail/varray.hpp b/bench/detail/varray.hpp index 454ba18..8dabe2d 100644 --- a/bench/detail/varray.hpp +++ b/bench/detail/varray.hpp @@ -33,7 +33,8 @@ #include #include //adl_move_swap -#include //adl_move_swap +#include // +#include #include "varray_util.hpp" @@ -1071,10 +1072,10 @@ public: typename aligned_storage ::value>::type temp_storage; - value_type * val_p = static_cast(static_cast(&temp_storage)); + value_type * val_p = move_detail::force_ptr(&temp_storage); sv::construct(dti(), val_p, ::boost::forward(args)...); // may throw sv::scoped_destructor d(val_p); - sv::assign(position, ::boost::move(*val_p)); // may throw + sv::assign(position, ::boost::move(*move_detail::launder(val_p))); // may throw } return position; @@ -1114,10 +1115,10 @@ public: sv::move_backward(position, this->end() - 2, this->end() - 1);/*may throw*/\ typename aligned_storage\ ::value>::type temp_storage;\ - value_type * val_p = static_cast(static_cast(&temp_storage));\ + value_type * val_p = move_detail::force_ptr(&temp_storage);\ sv::construct(dti(), val_p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ sv::scoped_destructor d(val_p);\ - sv::assign(position, ::boost::move(*val_p));/*may throw*/\ + sv::assign(position, ::boost::move(*move_detail::launder(val_p)));/*may throw*/\ }\ return position;\ }\ @@ -1582,7 +1583,7 @@ private: storage_type; storage_type temp_storage; - value_type * temp_ptr = static_cast(static_cast(&temp_storage)); + value_type * temp_ptr = move_detail::force_ptr(&temp_storage); ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size()); ::memcpy(this->data(), other.data(), sizeof(Value) * other.size()); @@ -1626,7 +1627,7 @@ private: sizeof(value_type), alignment_of::value >::type temp_storage; - value_type * temp_ptr = static_cast(static_cast(&temp_storage)); + value_type * temp_ptr = move_detail::force_ptr(&temp_storage); ::memcpy(temp_ptr, (addressof)(*first_sm), sizeof(value_type)); ::memcpy((addressof)(*first_sm), (addressof)(*first_la), sizeof(value_type)); ::memcpy((addressof)(*first_la), temp_ptr, sizeof(value_type)); diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 503a80b..038b8b4 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -545,7 +545,7 @@ struct vector_alloc_holder inline const allocator_type &alloc() const BOOST_NOEXCEPT_OR_NOTHROW { return *this; } - inline const pointer &start() const BOOST_NOEXCEPT_OR_NOTHROW + inline pointer start() const BOOST_NOEXCEPT_OR_NOTHROW { return m_start; } inline size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW { return m_capacity; } @@ -2807,12 +2807,19 @@ private: } } + #ifdef _MSC_VER + #pragma warning (push) + #pragma warning(disable: 4702) //Disable unreachable code warning + #endif template inline iterator priv_insert_forward_range_no_capacity (T * const, const size_type, const InsertionProxy , version_0) { return alloc_holder_t::on_capacity_overflow(), iterator(); } + #ifdef _MSC_VER + #pragma warning (pop) + #endif template BOOST_CONTAINER_NOINLINE iterator priv_insert_forward_range_no_capacity