Skip to content

Commit

Permalink
Add test_string_copy_assign_pocca_sso().
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej committed Jul 28, 2023
1 parent 6f8a3cb commit 0baefec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/std/tests/VSO_0000000_allocator_propagation/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <set>
#include <string>
Expand Down Expand Up @@ -635,6 +636,31 @@ void test_string_copy_assign(const size_t id1, const size_t id2, const size_t id
assert(dst.get_allocator().id() == id3);
}

void test_string_copy_assign_pocca_sso() {
// GH-3862 fixed a bug where the POCCA codepath in basic_string's copy assignment operator mishandled
// the scenario where the string on the right hand side has a large capacity but a small size - so while
// the RHS has dynamically allocated memory, the LHS should activate the Small String Optimization.

using Al = CopyAlloc<char>;
using Str = basic_string<char, char_traits<char>, Al>;

Str left{Al{11}};
Str right{Al{22}};

left.assign(5, 'a');

right.assign(1729, 'x');
right.assign(7, 'y');

assert(left == "aaaaa");
assert(right == "yyyyyyy");

left = right;

assert(left == "yyyyyyy");
assert(right == "yyyyyyy");
}

void test_string_move_ctor() {
basic_string<char32_t, char_traits<char32_t>, StationaryAlloc<char32_t>> src(
{5, 10, 20, 30}, StationaryAlloc<char32_t>(11));
Expand Down Expand Up @@ -770,6 +796,8 @@ void test_string() {
test_string_copy_assign<CopyAlloc<char32_t>>(11, 22, 11); // POCCA, non-equal allocators
test_string_copy_assign<CopyEqualAlloc<char32_t>>(11, 22, 11); // POCCA, always-equal allocators

test_string_copy_assign_pocca_sso();

test_string_move_ctor();

test_string_move_alloc_ctor(11, 11); // equal allocators
Expand Down

0 comments on commit 0baefec

Please sign in to comment.