aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/basic_string.tcc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-02-01 11:41:48 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2017-02-01 11:41:48 +0000
commit11d10beb5762c48de90a004368df2c2863b33d7a (patch)
treeaab5154423488af538040a2d8a5b37c2dcb566bb /libstdc++-v3/include/bits/basic_string.tcc
parenta0deb9925478be3738a87f40902c829d867f8f79 (diff)
PR libstdc++/79254 simplify exception-safety in copy assignment
PR libstdc++/79254 * config/abi/pre/gnu.ver: Remove recently added symbols. * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (basic_string::_M_copy_assign): Remove. (basic_string::operator=(const basic_string&)): Don't dispatch to _M_copy_assign. If source object is small just deallocate, otherwise perform new allocation before making any changes. * include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI] (basic_string::_M_copy_assign(const basic_string&, true_type)): Remove. * testsuite/21_strings/basic_string/allocator/char/copy_assign.cc: Test cases where the allocators are equal or the string is small. * testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc: Likewise. From-SVN: r245085
Diffstat (limited to 'libstdc++-v3/include/bits/basic_string.tcc')
-rw-r--r--libstdc++-v3/include/bits/basic_string.tcc64
1 files changed, 0 insertions, 64 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index adc8b853137..41b7fa196b0 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -275,70 +275,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
-#if __cplusplus >= 201103L
- template<typename _CharT, typename _Traits, typename _Alloc>
- void
- basic_string<_CharT, _Traits, _Alloc>::
- _M_copy_assign(const basic_string& __str, true_type)
- {
- struct _Guard // RAII type for strong exception-safety guarantee.
- {
- // Takes ownership of string's original state.
- _Guard(basic_string* __self)
- : _M_self(__self), _M_alloc(std::move(__self->_M_get_allocator())),
- _M_ptr(__self->_M_data()),
- _M_capacity(__self->_M_allocated_capacity), _M_len(__self->length())
- {
- __self->_M_data(__self->_M_local_data());
- __self->_M_length(0);
- }
-
- // Restores string's original state if _M_release() was not called.
- ~_Guard()
- {
- if (_M_ptr)
- {
- _M_self->_M_get_allocator() = std::move(_M_alloc);
- _M_self->_M_data(_M_ptr);
- _M_self->_M_capacity(_M_capacity);
- _M_self->_M_length(_M_len);
- }
- }
-
- _Guard(const _Guard&) = delete;
- _Guard& operator=(const _Guard&) = delete;
-
- void _M_release()
- {
- // Original state can be freed now.
- _Alloc_traits::deallocate(_M_alloc, _M_ptr, _M_capacity + 1);
- _M_ptr = nullptr;
- }
-
- basic_string* _M_self;
- allocator_type _M_alloc;
- pointer _M_ptr;
- size_type _M_capacity;
- size_type _M_len;
- };
-
- if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
- && _M_get_allocator() != __str._M_get_allocator())
- {
- // The propagating allocator cannot free existing storage.
- _Guard __guard(this);
- _M_get_allocator() = __str._M_get_allocator();
- this->_M_assign(__str);
- __guard._M_release();
- }
- else
- {
- _M_get_allocator() = __str._M_get_allocator();
- this->_M_assign(__str);
- }
- }
-#endif
-
template<typename _CharT, typename _Traits, typename _Alloc>
void
basic_string<_CharT, _Traits, _Alloc>::