diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2016-03-09 18:08:29 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2016-03-09 18:08:29 +0000 |
commit | ffc888bc09120f904c66d764ac6943b1ef739395 (patch) | |
tree | c3dedb55e134757d53b8681e3ca6f3c88ad4d3c6 /libcxx/test/std/strings/basic.string/string.modifiers | |
parent | 2648d42ecc80fab801b759c5b30da72a726c0223 (diff) | |
download | bcm5719-llvm-ffc888bc09120f904c66d764ac6943b1ef739395.tar.gz bcm5719-llvm-ffc888bc09120f904c66d764ac6943b1ef739395.zip |
Implement LWG#2579: Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assign
llvm-svn: 263042
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.modifiers')
-rw-r--r-- | libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp index 2bc5dd223e6..04954334bc0 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp @@ -15,7 +15,9 @@ #include <string> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" +#include "test_allocator.h" template <class S> void @@ -26,6 +28,16 @@ test(S s, S str, S expected) assert(s == expected); } +template <class S> +void +testAlloc(S s, S str, const typename S::allocator_type& a) +{ + s.assign(str); + assert(s.__invariants()); + assert(s == str); + assert(s.get_allocator() == a); +} + int main() { { @@ -50,7 +62,22 @@ int main() test(S("12345678901234567890"), S("1234567890"), S("1234567890")); test(S("12345678901234567890"), S("12345678901234567890"), S("12345678901234567890")); + + testAlloc(S(), S(), std::allocator<char>()); + testAlloc(S(), S("12345"), std::allocator<char>()); + testAlloc(S(), S("1234567890"), std::allocator<char>()); + testAlloc(S(), S("12345678901234567890"), std::allocator<char>()); + } + + { // LWG#5579 make sure assign takes the allocators where appropriate + typedef other_allocator<char> A; // has POCCA --> true + typedef std::basic_string<char, std::char_traits<char>, A> S; + testAlloc(S(A(5)), S(A(3)), A(3)); + testAlloc(S(A(5)), S("1"), A()); + testAlloc(S(A(5)), S("1", A(7)), A(7)); + testAlloc(S(A(5)), S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), A(7)); } + #if TEST_STD_VER >= 11 { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; @@ -74,9 +101,14 @@ int main() test(S("12345678901234567890"), S("1234567890"), S("1234567890")); test(S("12345678901234567890"), S("12345678901234567890"), S("12345678901234567890")); + + testAlloc(S(), S(), min_allocator<char>()); + testAlloc(S(), S("12345"), min_allocator<char>()); + testAlloc(S(), S("1234567890"), min_allocator<char>()); + testAlloc(S(), S("12345678901234567890"), min_allocator<char>()); } #endif -#if __cplusplus > 201402L +#if TEST_STD_VER > 14 { typedef std::string S; static_assert(noexcept(S().assign(S())), ""); // LWG#2063 |