Skip to content

Commit a0848ce

Browse files
committed
Fixes #295 ("Bug in small_vector::swap")
1 parent 83b8d57 commit a0848ce

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

doc/container.qbk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ use [*Boost.Container]? There are several reasons for that:
14301430
* Fixed bugs/issues:
14311431
* [@https://github.com/boostorg/container/issues/261 GitHub #261: ['"End iterators are not dereferencable"]].
14321432
* [@https://github.com/boostorg/container/issues/288 GitHub #288: ['"Compile error when using flat_map::extract_sequence with small_vector"]].
1433+
* [@https://github.com/boostorg/container/issues/295 GitHub #295: ['"Bug in small_vector::swap"]].
14331434

14341435
[endsect]
14351436

include/boost/container/vector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,7 +2765,7 @@ class vector
27652765
//Move internal memory data to the internal memory data of the target, this can throw
27662766
BOOST_ASSERT(extmem.capacity() >= intmem.size());
27672767
::boost::container::uninitialized_move_alloc_n
2768-
(intmem.get_stored_allocator(), this->priv_raw_begin(), intmem.size(), extmem.priv_raw_begin());
2768+
(intmem.get_stored_allocator(), intmem.priv_raw_begin(), intmem.size(), extmem.priv_raw_begin());
27692769

27702770
//Exception not thrown, commit new state
27712771
extmem.m_holder.set_stored_size(intmem.size());
@@ -2776,7 +2776,7 @@ class vector
27762776

27772777
//Destroy moved elements from intmem
27782778
boost::container::destroy_alloc_n
2779-
( intmem.get_stored_allocator(), this->priv_raw_begin()
2779+
( intmem.get_stored_allocator(), intmem.priv_raw_begin()
27802780
, intmem.size());
27812781

27822782
//Adopt dynamic buffer

test/small_vector_test.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//////////////////////////////////////////////////////////////////////////////
23
//
34
// (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
@@ -297,10 +298,10 @@ bool test_swap()
297298
v.push_back(int(i));
298299
}
299300
vec w;
300-
const std::size_t v_size = v.size();
301-
const std::size_t w_size = w.size();
301+
vec v_copy = v;
302+
vec w_copy = w;
302303
v.swap(w);
303-
if(v.size() != w_size || w.size() != v_size)
304+
if (w != v_copy || v != w_copy)
304305
return false;
305306
}
306307
{ //v smaller than static capacity, w empty
@@ -309,10 +310,10 @@ bool test_swap()
309310
v.push_back(int(i));
310311
}
311312
vec w;
312-
const std::size_t v_size = v.size();
313-
const std::size_t w_size = w.size();
313+
vec v_copy = v;
314+
vec w_copy = w;
314315
v.swap(w);
315-
if(v.size() != w_size || w.size() != v_size)
316+
if (w != v_copy || v != w_copy)
316317
return false;
317318
}
318319
{ //v bigger than static capacity, w enough capacity for static
@@ -324,10 +325,10 @@ bool test_swap()
324325
for (std::size_t i = 0, max = w.capacity() / 2; i != max; ++i) {
325326
w.push_back(int(i));
326327
}
327-
const std::size_t v_size = v.size();
328-
const std::size_t w_size = w.size();
328+
vec v_copy = v;
329+
vec w_copy = w;
329330
v.swap(w);
330-
if (v.size() != w_size || w.size() != v_size)
331+
if (w != v_copy || v != w_copy)
331332
return false;
332333
}
333334
{ //v & w smaller than static capacity
@@ -339,10 +340,10 @@ bool test_swap()
339340
for(std::size_t i = 0, max = w.capacity()/2; i != max; ++i){
340341
w.push_back(int(i));
341342
}
342-
const std::size_t v_size = v.size();
343-
const std::size_t w_size = w.size();
343+
vec v_copy = v;
344+
vec w_copy = w;
344345
v.swap(w);
345-
if(v.size() != w_size || w.size() != v_size)
346+
if (w != v_copy || v != w_copy)
346347
return false;
347348
}
348349
{ //v & w bigger than static capacity
@@ -354,10 +355,10 @@ bool test_swap()
354355
for(std::size_t i = 0, max = w.capacity()*2; i != max; ++i){
355356
w.push_back(int(i));
356357
}
357-
const std::size_t v_size = v.size();
358-
const std::size_t w_size = w.size();
358+
vec v_copy = v;
359+
vec w_copy = w;
359360
v.swap(w);
360-
if(v.size() != w_size || w.size() != v_size)
361+
if (w != v_copy || v != w_copy)
361362
return false;
362363
}
363364

0 commit comments

Comments
 (0)