This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On 01/02/17 11:42 +0000, Jonathan Wakely wrote:
On 27/01/17 16:16 +0000, Jonathan Wakely wrote:This implements the strong exception-safety guarantee that is required by [string.require] p2, which the new string can fail to meet when propagate_on_container_copy_assignment (POCCA) is true. The solution is to define a helper that takes ownership of the string's memory (and also the associated allocator, length and capacity) and either deallocates it after the assignment, or swaps it back in if an exception happens (i.e. commit or rollback). PR libstdc++/79254 * config/abi/pre/gnu.ver: Add new symbols. * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (basic_string::_M_copy_assign): New overloaded functions to perform copy assignment. (basic_string::operator=(const basic_string&)): Dispatch to _M_copy_assign. * include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI] (basic_string::_M_copy_assign(const basic_string&, true_type)): Define, performing rollback on exception. * testsuite/21_strings/basic_string/allocator/char/copy_assign.cc: Test exception-safety guarantee. * testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc: Likewise. * testsuite/util/testsuite_allocator.h (uneq_allocator::swap): Make std::swap visible. The backports for the branches will be a bit different, as we can't add new exports to closed symbol versions, so I'll keep everything in operator= instead of tag dispatching. The POCCA code path will still be dependent on a constant expression, so should be optimized away for most allocators.Whlie working on the backport of this I realised the RAII commit-and-rollback approach is a lot more complicated than simply doing the new allocation before making any changes to *this.
Here's the backport for the branches, which shows that the new approach is much closer to the original code and much simpler. Tested x86_64-linux, committed to gcc-6-branch and gcc-5-branch.
Attachment:
gcc6.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |