Return start() pointer by value to limit aliasing

This commit is contained in:
Ion Gaztañaga
2024-04-15 12:51:44 +02:00
parent 978bbb113a
commit 03abe8c02c
2 changed files with 16 additions and 8 deletions

View File

@@ -33,7 +33,8 @@
#include <boost/container/detail/type_traits.hpp>
#include <boost/move/adl_move_swap.hpp> //adl_move_swap
#include <boost/move/detail/force_ptr.hpp> //adl_move_swap
#include <boost/move/detail/launder.hpp> //
#include <boost/move/detail/force_ptr.hpp>
#include "varray_util.hpp"
@@ -1071,10 +1072,10 @@ public:
typename aligned_storage
<sizeof(value_type), alignment_of<value_type>::value>::type temp_storage;
value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage));
value_type * val_p = move_detail::force_ptr<value_type*>(&temp_storage);
sv::construct(dti(), val_p, ::boost::forward<Args>(args)...); // may throw
sv::scoped_destructor<value_type> 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\
<sizeof(value_type), alignment_of<value_type>::value>::type temp_storage;\
value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage));\
value_type * val_p = move_detail::force_ptr<value_type*>(&temp_storage);\
sv::construct(dti(), val_p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\
sv::scoped_destructor<value_type> 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<value_type*>(static_cast<void*>(&temp_storage));
value_type * temp_ptr = move_detail::force_ptr<value_type*>(&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>::value
>::type temp_storage;
value_type * temp_ptr = static_cast<value_type*>(static_cast<void*>(&temp_storage));
value_type * temp_ptr = move_detail::force_ptr<value_type*>(&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));

View File

@@ -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 <class InsertionProxy>
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 <class InsertionProxy>
BOOST_CONTAINER_NOINLINE iterator priv_insert_forward_range_no_capacity