Add non-const overload of std::string::data()
authorJonathan Wakely <jwakely@redhat.com>
Wed, 13 Jul 2016 11:08:37 +0000 (12:08 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 13 Jul 2016 11:08:37 +0000 (12:08 +0100)
commitceea48fc64eb7d5fe8c2ecfd61f6cda7918e40c1
tree13cd8c4c8df5f3c9af5fdd00260d2e74accbc60d
parentc7ed8938d6a62e532c89c25f54851b8c4fef1d88
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
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/ext_ptr.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/operations/data/char/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc [new file with mode: 0644]