diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-06-21 23:01:25 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-06-21 23:01:25 +0100 |
commit | cda121ac7a50e53faa61f282f6ef21b58fe8e7fd (patch) | |
tree | eca3dd7424fe9f58436af970b91afff468a6e0c2 /libstdc++-v3/include | |
parent | 5cfd86209522dac51933a7d3c92135f392b16131 (diff) | |
download | gcc-cda121ac7a50e53faa61f282f6ef21b58fe8e7fd.tar.gz |
PR libstdc++/83328 add correct basic_string::insert for initializer_list
The SSO basic_string has a non-standard insert(iterator, initializer_list)
overload, from a C++0x draft. This adds the correct overload, while also
preserving the old one so that the old symbol is still exported from the
library.
The COW basic_string doesn't have any of the C++11 changes to the insert
overloads (they all still have non-const iterator parameters and the
ones that should return an iterator still return void). This doesn't
make any change to the COW string.
PR libstdc++/83328
* acinclude.m4 (libtool_VERSION): Bump to 6:26:0.
* config/abi/pre/gnu.ver: Add GLIBCXX_3.4.26 and export new symbol.
* configure: Regenerate.
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
(basic_string::insert(const_iterator, initializer_list<C>)): Add.
[_GLIBCXX_USE_CXX11_ABI && !_GLIBCXX_DEFINING_STRING_INSTANTIATIONS]
(basic_string::insert(iterator, initializer_list<C>)): Suppress
definition.
* include/debug/string (basic_string::insert(iterator, C)): Change
first parameter to const_iterator.
(basic_string::insert(iterator, size_type, C)): Likewise. Change
return type to iterator.
(basic_string::insert(iterator, InputIterator, InputIterator)):
Likewise.
(basic_string::insert(iterator, initializer_list<C>)): Change first
parameter to const_iterator and return type to iterator.
* src/c++11/string-inst.cc: Extend comment.
* testsuite/21_strings/basic_string/modifiers/insert/char/83328.cc:
New.
* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/83328.cc:
New.
* testsuite/util/testsuite_abi.cc: Add new symbol version.
From-SVN: r261866
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/string | 29 |
2 files changed, 23 insertions, 13 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 2e6e1c6e5da..a77074da249 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -1598,12 +1598,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __l The initializer_list of characters to insert. * @throw std::length_error If new length exceeds @c max_size(). */ + iterator + insert(const_iterator __p, initializer_list<_CharT> __l) + { return this->insert(__p, __l.begin(), __l.end()); } + +#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS + // See PR libstdc++/83328 void insert(iterator __p, initializer_list<_CharT> __l) { _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); this->insert(__p - begin(), __l.begin(), __l.size()); } +#endif #endif // C++11 /** diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index 0aa5e9cf825..aa611b2d4a9 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -544,7 +544,7 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>, } iterator - insert(iterator __p, _CharT __c) + insert(const_iterator __p, _CharT __c) { __glibcxx_check_insert(__p); typename _Base::iterator __res = _Base::insert(__p.base(), __c); @@ -552,37 +552,40 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>, return iterator(__res, this); } - void - insert(iterator __p, size_type __n, _CharT __c) + iterator + insert(const_iterator __p, size_type __n, _CharT __c) { __glibcxx_check_insert(__p); - _Base::insert(__p.base(), __n, __c); + typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c); this->_M_invalidate_all(); + return iterator(__res, this); } template<typename _InputIterator> - void - insert(iterator __p, _InputIterator __first, _InputIterator __last) + iterator + insert(const_iterator __p, _InputIterator __first, _InputIterator __last) { typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; __glibcxx_check_insert_range2(__p, __first, __last, __dist); + typename _Base::iterator __res; if (__dist.second >= __dp_sign) - _Base::insert(__p.base(), __gnu_debug::__unsafe(__first), - __gnu_debug::__unsafe(__last)); + __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first), + __gnu_debug::__unsafe(__last)); else - _Base::insert(__p.base(), __first, __last); - + __res = _Base::insert(__p.base(), __first, __last); this->_M_invalidate_all(); + return iterator(__res, this); } #if __cplusplus >= 201103L - void - insert(iterator __p, std::initializer_list<_CharT> __l) + iterator + insert(const_iterator __p, std::initializer_list<_CharT> __l) { __glibcxx_check_insert(__p); - _Base::insert(__p.base(), __l); + const auto __res = _Base::insert(__p.base(), __l); this->_M_invalidate_all(); + return iterator(__res, this); } #endif // C++11 |