diff --git a/doc/container.qbk b/doc/container.qbk index 94d3ca78..705cdc32 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1430,6 +1430,7 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs/issues: * [@https://github.com/boostorg/container/issues/261 GitHub #261: ['"End iterators are not dereferencable"]]. * [@https://github.com/boostorg/container/issues/288 GitHub #288: ['"Compile error when using flat_map::extract_sequence with small_vector"]]. + * [@https://github.com/boostorg/container/issues/295 GitHub #295: ['"Bug in small_vector::swap"]]. [endsect] diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 26de2b08..aecb7dd2 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -2765,7 +2765,7 @@ class vector //Move internal memory data to the internal memory data of the target, this can throw BOOST_ASSERT(extmem.capacity() >= intmem.size()); ::boost::container::uninitialized_move_alloc_n - (intmem.get_stored_allocator(), this->priv_raw_begin(), intmem.size(), extmem.priv_raw_begin()); + (intmem.get_stored_allocator(), intmem.priv_raw_begin(), intmem.size(), extmem.priv_raw_begin()); //Exception not thrown, commit new state extmem.m_holder.set_stored_size(intmem.size()); @@ -2776,7 +2776,7 @@ class vector //Destroy moved elements from intmem boost::container::destroy_alloc_n - ( intmem.get_stored_allocator(), this->priv_raw_begin() + ( intmem.get_stored_allocator(), intmem.priv_raw_begin() , intmem.size()); //Adopt dynamic buffer diff --git a/test/small_vector_test.cpp b/test/small_vector_test.cpp index 1d68699a..80c3a4eb 100644 --- a/test/small_vector_test.cpp +++ b/test/small_vector_test.cpp @@ -1,3 +1,4 @@ + ////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost @@ -297,10 +298,10 @@ bool test_swap() v.push_back(int(i)); } vec w; - const std::size_t v_size = v.size(); - const std::size_t w_size = w.size(); + vec v_copy = v; + vec w_copy = w; v.swap(w); - if(v.size() != w_size || w.size() != v_size) + if (w != v_copy || v != w_copy) return false; } { //v smaller than static capacity, w empty @@ -309,10 +310,10 @@ bool test_swap() v.push_back(int(i)); } vec w; - const std::size_t v_size = v.size(); - const std::size_t w_size = w.size(); + vec v_copy = v; + vec w_copy = w; v.swap(w); - if(v.size() != w_size || w.size() != v_size) + if (w != v_copy || v != w_copy) return false; } { //v bigger than static capacity, w enough capacity for static @@ -324,10 +325,10 @@ bool test_swap() for (std::size_t i = 0, max = w.capacity() / 2; i != max; ++i) { w.push_back(int(i)); } - const std::size_t v_size = v.size(); - const std::size_t w_size = w.size(); + vec v_copy = v; + vec w_copy = w; v.swap(w); - if (v.size() != w_size || w.size() != v_size) + if (w != v_copy || v != w_copy) return false; } { //v & w smaller than static capacity @@ -339,10 +340,10 @@ bool test_swap() for(std::size_t i = 0, max = w.capacity()/2; i != max; ++i){ w.push_back(int(i)); } - const std::size_t v_size = v.size(); - const std::size_t w_size = w.size(); + vec v_copy = v; + vec w_copy = w; v.swap(w); - if(v.size() != w_size || w.size() != v_size) + if (w != v_copy || v != w_copy) return false; } { //v & w bigger than static capacity @@ -354,10 +355,10 @@ bool test_swap() for(std::size_t i = 0, max = w.capacity()*2; i != max; ++i){ w.push_back(int(i)); } - const std::size_t v_size = v.size(); - const std::size_t w_size = w.size(); + vec v_copy = v; + vec w_copy = w; v.swap(w); - if(v.size() != w_size || w.size() != v_size) + if (w != v_copy || v != w_copy) return false; }