This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Add non-const overload of std::string::data()
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 13 Jul 2016 15:59:09 +0100
- Subject: Re: [PATCH] Add non-const overload of std::string::data()
- Authentication-results: sourceware.org; auth=none
- References: <20160713111244.GA12384@redhat.com>
On 13/07/16 12:12 +0100, Jonathan Wakely wrote:
Also fix confusion between pointer and _CharT*, so that allocators with
fancy pointers work correctly.
The _M_data() function returns pointer, but we were using it where
_CharT* was required. This introduces a new _M_c_str() function which
returns a _CharT* instead, and uses that for c_str() and both
overloads of data().
Most places using _M_data() can just use data() instead, as they only
need a const _CharT*. A few need to use _M_c_str() to get _CharT* so
they can write to it (they could use the new data() overload, except
that it's not defined until C++17).
Tested x86_64-linux, committed to trunk.
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (_M_c_str):
I forgot to add the new exports to the commit, new patch coming