From 5fe2dba504be153643cb8f82eec0a46f97f3d179 Mon Sep 17 00:00:00 2001 From: Tobias Reh Date: Fri, 24 Feb 2017 15:33:30 +0100 Subject: [PATCH 1/2] emplace_back must return reference to back(), not to *end() --- include/boost/container/vector.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 5d7d765..3fdd003 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -1735,9 +1735,10 @@ class vector { if (BOOST_LIKELY(this->room_enough())){ //There is more memory, just construct a new object at the end - allocator_traits_type::construct(this->m_holder.alloc(), this->priv_raw_end(), ::boost::forward(args)...); + T* const p = this->priv_raw_end(); + allocator_traits_type::construct(this->m_holder.alloc(), p, ::boost::forward(args)...); ++this->m_holder.m_size; - return *this->priv_raw_end(); + return *p; } else{ typedef container_detail::insert_emplace_proxy type; From 1261ac33089cbc08108b4beaed97f307270892a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 24 Feb 2017 22:07:20 +0100 Subject: [PATCH 2/2] Fix emplace_back return type also in compilers without variadic templates. Update changelog. --- doc/container.qbk | 5 +++-- include/boost/container/vector.hpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index aa31f0a..341c16c 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1217,8 +1217,9 @@ use [*Boost.Container]? There are several reasons for that: [section:release_notes_boost_1_64_00 Boost 1.64 Release] * Fixed bugs: - * [@https://svn.boost.org/trac/boost/ticket/12749 Trac #12749: ['"container::pmr::polymorphic_allocator compilation error"]]. - * [@https://svn.boost.org/trac/boost/ticket/11333 Trac #11333: ['"boost::basic_string_ref should interop with boost::container::basic_string"]]. + * [@https://svn.boost.org/trac/boost/ticket/12749 Trac #12749: ['"container::pmr::polymorphic_allocator compilation error"]]. + * [@https://svn.boost.org/trac/boost/ticket/11333 Trac #11333: ['"boost::basic_string_ref should interop with boost::container::basic_string"]]. + * [@https://github.com/boostorg/container/pull/45 GitHub #45: ['"emplace_back must return reference to back(), not to *end()"]]. [endsect] diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 3fdd003..7456ee8 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -1794,10 +1794,11 @@ class vector BOOST_CONTAINER_FORCEINLINE reference emplace_back(BOOST_MOVE_UREF##N)\ {\ if (BOOST_LIKELY(this->room_enough())){\ + T* const p = this->priv_raw_end();\ allocator_traits_type::construct (this->m_holder.alloc()\ , this->priv_raw_end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ ++this->m_holder.m_size;\ - return *this->priv_raw_end();\ + return *p;\ }\ else{\ typedef container_detail::insert_emplace_proxy_arg##N type;\