Author: marshall Date: Wed Mar 9 12:08:29 2016 New Revision: 263042 URL: http://llvm.org/viewvc/llvm-project?rev=263042&view=rev Log: Implement LWG#2579: Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assign
Modified: libcxx/trunk/include/string libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp Modified: libcxx/trunk/include/string URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=263042&r1=263041&r2=263042&view=diff ============================================================================== --- libcxx/trunk/include/string (original) +++ libcxx/trunk/include/string Wed Mar 9 12:08:29 2016 @@ -1551,7 +1551,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reference back() const; _LIBCPP_INLINE_VISIBILITY - basic_string& assign(const basic_string& __str); + basic_string& assign(const basic_string& __str) { return *this = __str; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_string& assign(basic_string&& str) @@ -2489,7 +2489,7 @@ basic_string<_CharT, _Traits, _Allocator if (this != &__str) { __copy_assign_alloc(__str); - assign(__str); + assign(__str.data(), __str.size()); } return *this; } @@ -2581,14 +2581,6 @@ basic_string<_CharT, _Traits, _Allocator } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str) -{ - return assign(__str.data(), __str.size()); -} - -template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) { Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp?rev=263042&r1=263041&r2=263042&view=diff ============================================================================== --- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp (original) +++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp Wed Mar 9 12:08:29 2016 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits