diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2016-07-13 12:08:37 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2016-07-13 12:08:37 +0100 |
commit | ceea48fc64eb7d5fe8c2ecfd61f6cda7918e40c1 (patch) | |
tree | 13cd8c4c8df5f3c9af5fdd00260d2e74accbc60d /libstdc++-v3/include/bits/basic_string.tcc | |
parent | c7ed8938d6a62e532c89c25f54851b8c4fef1d88 (diff) |
Add non-const overload of std::string::data()
Also fix confusion between pointer and _CharT*, so that allocators with
fancy pointers work correctly.
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (_M_c_str):
New function.
(_M_disjunct, basic_string(const basic_string&, size_t)): Use data()
instead of _M_data().
(basic_string(const basic_string&, size_t, size_t, const _Alloc&)):
Likewise.
(append(const basic_string&)): Likewise.
(append(const basic_string&, size_type, size_type)): Likewise.
(assign(const basic_string&, size_type, size_type)): Likewise.
(insert(size_type, const basic_string&)): Likewise.
(insert(size_type, const basic_string&, size_type, size_type)):
Likewise.
(replace(size_type, size_type, const basic_string&, size_type,
size_type)): Likewise.
(replace(__const_iterator, __const_iterator, const basic_string&)):
Likewise.
(c_str(), data()): Use c_str() instead of _M_data().
(data()): Add non-const overload as per LWG 2391 and P0272R1.
(compare(const basic_string&)): Use data() instead of _M_data().
[!_GLIBCXX_USE_CXX11_ABI] (data()): Add non-const overload.
* include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI] (_M_mutate):
Pass raw pointers to _S_copy.
(_M_erase, _M_replace_aux): Pass raw pointers to _S_move and
_S_assign.
(find(const _CharT*, size_type, size_type)): Use data instead of
_M_data().
* testsuite/21_strings/basic_string/allocator/char/ext_ptr.cc: New.
* testsuite/21_strings/basic_string/operations/data/char/2.cc: New.
* testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc: New.
From-SVN: r238291
Diffstat (limited to 'libstdc++-v3/include/bits/basic_string.tcc')
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 2b6644d1c49..1e6d38eb0f3 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -315,14 +315,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION size_type __new_capacity = length() + __len2 - __len1; pointer __r = _M_create(__new_capacity, capacity()); + _CharT* __p = std::__addressof(*__r); if (__pos) - this->_S_copy(__r, _M_data(), __pos); + this->_S_copy(__p, _M_c_str(), __pos); if (__s && __len2) - this->_S_copy(__r + __pos, __s, __len2); + this->_S_copy(__p + __pos, __s, __len2); if (__how_much) - this->_S_copy(__r + __pos + __len2, - _M_data() + __pos + __len1, __how_much); + this->_S_copy(__p + __pos + __len2, + _M_c_str() + __pos + __len1, __how_much); _M_dispose(); _M_data(__r); @@ -336,8 +337,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { const size_type __how_much = length() - __pos - __n; + _CharT* __p = _M_c_str(); if (__how_much && __n) - this->_S_move(_M_data() + __pos, _M_data() + __pos + __n, __how_much); + this->_S_move(__p + __pos, __p + __pos + __n, __how_much); _M_set_length(length() - __n); } @@ -400,7 +402,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__new_size <= this->capacity()) { - pointer __p = this->_M_data() + __pos1; + _CharT* __p = this->_M_c_str() + __pos1; const size_type __how_much = __old_size - __pos1 - __n1; if (__how_much && __n1 != __n2) @@ -410,7 +412,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->_M_mutate(__pos1, __n1, 0, __n2); if (__n2) - this->_S_assign(this->_M_data() + __pos1, __n2, __c); + this->_S_assign(this->_M_c_str() + __pos1, __n2, __c); this->_M_set_length(__new_size); return *this; @@ -1179,7 +1181,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __glibcxx_requires_string_len(__s, __n); const size_type __size = this->size(); - const _CharT* __data = _M_data(); + const _CharT* __data = data(); if (__n == 0) return __pos <= __size ? __pos : npos; |