Commit 2d60da10 by Jonathan Wakely Committed by Jonathan Wakely

Revert "Add non-const overload of std::string::data()"

This reverts r238291 aka 4300aa2087d90cd2d55852fa38f082a89bc7e72d.

From-SVN: r238303
parent 6fa3d4b4
2016-07-13 Jonathan Wakely <jwakely@redhat.com>
Revert "Add non-const overload of std::string::data()".
2016-07-13 Ville Voutilainen <ville.voutilainen@gmail.com> 2016-07-13 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement P0307R2, Making Optional Greater Equal Again. Implement P0307R2, Making Optional Greater Equal Again.
......
...@@ -155,11 +155,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -155,11 +155,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
#endif #endif
} }
// Get a raw pointer (rather than _Alloc::pointer).
_CharT*
_M_c_str() const
{ return std::__addressof(*_M_dataplus._M_p); }
void void
_M_capacity(size_type __capacity) _M_capacity(size_type __capacity)
{ _M_allocated_capacity = __capacity; } { _M_allocated_capacity = __capacity; }
...@@ -290,8 +285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -290,8 +285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
bool bool
_M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
{ {
return (less<const _CharT*>()(__s, data()) return (less<const _CharT*>()(__s, _M_data())
|| less<const _CharT*>()(data() + this->size(), __s)); || less<const _CharT*>()(_M_data() + this->size(), __s));
} }
// When __n = 1 way faster than the general multichar // When __n = 1 way faster than the general multichar
...@@ -416,7 +411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -416,7 +411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
size_type __n = npos) size_type __n = npos)
: _M_dataplus(_M_local_data()) : _M_dataplus(_M_local_data())
{ {
const _CharT* __start = __str.data() const _CharT* __start = __str._M_data()
+ __str._M_check(__pos, "basic_string::basic_string"); + __str._M_check(__pos, "basic_string::basic_string");
_M_construct(__start, __start + __str._M_limit(__pos, __n)); _M_construct(__start, __start + __str._M_limit(__pos, __n));
} }
...@@ -432,8 +427,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -432,8 +427,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
size_type __n, const _Alloc& __a) size_type __n, const _Alloc& __a)
: _M_dataplus(_M_local_data(), __a) : _M_dataplus(_M_local_data(), __a)
{ {
const _CharT* __start = __str.data() const _CharT* __start
+ __str._M_check(__pos, "basic_string::basic_string"); = __str._M_data() + __str._M_check(__pos, "string::string");
_M_construct(__start, __start + __str._M_limit(__pos, __n)); _M_construct(__start, __start + __str._M_limit(__pos, __n));
} }
...@@ -1071,7 +1066,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1071,7 +1066,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/ */
basic_string& basic_string&
append(const basic_string& __str) append(const basic_string& __str)
{ return _M_append(__str.data(), __str.size()); } { return _M_append(__str._M_data(), __str.size()); }
/** /**
* @brief Append a substring. * @brief Append a substring.
...@@ -1088,7 +1083,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1088,7 +1083,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/ */
basic_string& basic_string&
append(const basic_string& __str, size_type __pos, size_type __n) append(const basic_string& __str, size_type __pos, size_type __n)
{ return _M_append(__str.data() { return _M_append(__str._M_data()
+ __str._M_check(__pos, "basic_string::append"), + __str._M_check(__pos, "basic_string::append"),
__str._M_limit(__pos, __n)); } __str._M_limit(__pos, __n)); }
...@@ -1221,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1221,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/ */
basic_string& basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n) assign(const basic_string& __str, size_type __pos, size_type __n)
{ return _M_replace(size_type(0), this->size(), __str.data() { return _M_replace(size_type(0), this->size(), __str._M_data()
+ __str._M_check(__pos, "basic_string::assign"), + __str._M_check(__pos, "basic_string::assign"),
__str._M_limit(__pos, __n)); } __str._M_limit(__pos, __n)); }
...@@ -1418,7 +1413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1418,7 +1413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
basic_string& basic_string&
insert(size_type __pos1, const basic_string& __str) insert(size_type __pos1, const basic_string& __str)
{ return this->replace(__pos1, size_type(0), { return this->replace(__pos1, size_type(0),
__str.data(), __str.size()); } __str._M_data(), __str.size()); }
/** /**
* @brief Insert a substring. * @brief Insert a substring.
...@@ -1441,7 +1436,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1441,7 +1436,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
basic_string& basic_string&
insert(size_type __pos1, const basic_string& __str, insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n) size_type __pos2, size_type __n)
{ return this->replace(__pos1, size_type(0), __str.data() { return this->replace(__pos1, size_type(0), __str._M_data()
+ __str._M_check(__pos2, "basic_string::insert"), + __str._M_check(__pos2, "basic_string::insert"),
__str._M_limit(__pos2, __n)); } __str._M_limit(__pos2, __n)); }
...@@ -1624,7 +1619,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1624,7 +1619,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/ */
basic_string& basic_string&
replace(size_type __pos, size_type __n, const basic_string& __str) replace(size_type __pos, size_type __n, const basic_string& __str)
{ return this->replace(__pos, __n, __str.data(), __str.size()); } { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
/** /**
* @brief Replace characters with value from another string. * @brief Replace characters with value from another string.
...@@ -1647,7 +1642,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1647,7 +1642,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
basic_string& basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str, replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2) size_type __pos2, size_type __n2)
{ return this->replace(__pos1, __n1, __str.data() { return this->replace(__pos1, __n1, __str._M_data()
+ __str._M_check(__pos2, "basic_string::replace"), + __str._M_check(__pos2, "basic_string::replace"),
__str._M_limit(__pos2, __n2)); } __str._M_limit(__pos2, __n2)); }
...@@ -1739,7 +1734,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1739,7 +1734,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
basic_string& basic_string&
replace(__const_iterator __i1, __const_iterator __i2, replace(__const_iterator __i1, __const_iterator __i2,
const basic_string& __str) const basic_string& __str)
{ return this->replace(__i1, __i2, __str.data(), __str.size()); } { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
/** /**
* @brief Replace range of characters with C substring. * @brief Replace range of characters with C substring.
...@@ -1980,29 +1975,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1980,29 +1975,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/ */
const _CharT* const _CharT*
c_str() const _GLIBCXX_NOEXCEPT c_str() const _GLIBCXX_NOEXCEPT
{ return _M_c_str(); } { return _M_data(); }
/** /**
* @brief Return const pointer to contents. * @brief Return const pointer to contents.
* *
* This is a pointer to internal data. Do not modify or dire things may * This is a handle to internal data. Do not modify or dire things may
* happen. * happen.
*/ */
const _CharT* const _CharT*
data() const _GLIBCXX_NOEXCEPT data() const _GLIBCXX_NOEXCEPT
{ return _M_c_str(); } { return _M_data(); }
#if __cplusplus > 201402L
/**
* @brief Return non-const pointer to contents.
*
* This is a pointer to the character sequence held by the string.
* Modifying the characters in the sequence is allowed.
*/
_CharT*
data() noexcept
{ return _M_c_str(); }
#endif
/** /**
* @brief Return copy of allocator used to construct this string. * @brief Return copy of allocator used to construct this string.
...@@ -2422,7 +2405,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -2422,7 +2405,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
const size_type __osize = __str.size(); const size_type __osize = __str.size();
const size_type __len = std::min(__size, __osize); const size_type __len = std::min(__size, __osize);
int __r = traits_type::compare(data(), __str.data(), __len); int __r = traits_type::compare(_M_data(), __str.data(), __len);
if (!__r) if (!__r)
__r = _S_compare(__size, __osize); __r = _S_compare(__size, __osize);
return __r; return __r;
...@@ -4378,12 +4361,6 @@ _GLIBCXX_END_NAMESPACE_CXX11 ...@@ -4378,12 +4361,6 @@ _GLIBCXX_END_NAMESPACE_CXX11
data() const _GLIBCXX_NOEXCEPT data() const _GLIBCXX_NOEXCEPT
{ return _M_data(); } { return _M_data(); }
#if __cplusplus > 201402L
_CharT*
data() noexcept
{ return _M_data(); }
#endif
/** /**
* @brief Return copy of allocator used to construct this string. * @brief Return copy of allocator used to construct this string.
*/ */
......
...@@ -315,15 +315,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -315,15 +315,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
size_type __new_capacity = length() + __len2 - __len1; size_type __new_capacity = length() + __len2 - __len1;
pointer __r = _M_create(__new_capacity, capacity()); pointer __r = _M_create(__new_capacity, capacity());
_CharT* __p = std::__addressof(*__r);
if (__pos) if (__pos)
this->_S_copy(__p, _M_c_str(), __pos); this->_S_copy(__r, _M_data(), __pos);
if (__s && __len2) if (__s && __len2)
this->_S_copy(__p + __pos, __s, __len2); this->_S_copy(__r + __pos, __s, __len2);
if (__how_much) if (__how_much)
this->_S_copy(__p + __pos + __len2, this->_S_copy(__r + __pos + __len2,
_M_c_str() + __pos + __len1, __how_much); _M_data() + __pos + __len1, __how_much);
_M_dispose(); _M_dispose();
_M_data(__r); _M_data(__r);
...@@ -337,9 +336,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -337,9 +336,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
const size_type __how_much = length() - __pos - __n; const size_type __how_much = length() - __pos - __n;
_CharT* __p = _M_c_str();
if (__how_much && __n) if (__how_much && __n)
this->_S_move(__p + __pos, __p + __pos + __n, __how_much); this->_S_move(_M_data() + __pos, _M_data() + __pos + __n, __how_much);
_M_set_length(length() - __n); _M_set_length(length() - __n);
} }
...@@ -402,7 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -402,7 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__new_size <= this->capacity()) if (__new_size <= this->capacity())
{ {
_CharT* __p = this->_M_c_str() + __pos1; pointer __p = this->_M_data() + __pos1;
const size_type __how_much = __old_size - __pos1 - __n1; const size_type __how_much = __old_size - __pos1 - __n1;
if (__how_much && __n1 != __n2) if (__how_much && __n1 != __n2)
...@@ -412,7 +410,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -412,7 +410,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
this->_M_mutate(__pos1, __n1, 0, __n2); this->_M_mutate(__pos1, __n1, 0, __n2);
if (__n2) if (__n2)
this->_S_assign(this->_M_c_str() + __pos1, __n2, __c); this->_S_assign(this->_M_data() + __pos1, __n2, __c);
this->_M_set_length(__new_size); this->_M_set_length(__new_size);
return *this; return *this;
...@@ -1181,7 +1179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1181,7 +1179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
__glibcxx_requires_string_len(__s, __n); __glibcxx_requires_string_len(__s, __n);
const size_type __size = this->size(); const size_type __size = this->size();
const _CharT* __data = data(); const _CharT* __data = _M_data();
if (__n == 0) if (__n == 0)
return __pos <= __size ? __pos : npos; return __pos <= __size ? __pos : npos;
......
// Copyright (C) 2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++11" }
#include <string>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
using C = char;
const C c = 'a';
using traits = std::char_traits<C>;
// basic_string is not required to support fancy pointers:
// http://cplusplus.github.io/LWG/lwg-closed.html#2084
using __gnu_test::CustomPointerAlloc;
void test01()
{
#if _GLIBCXX_USE_CXX11_ABI
bool test __attribute__((unused)) = true;
typedef CustomPointerAlloc<C> alloc_type;
typedef std::basic_string<C, traits, alloc_type> test_type;
test_type v;
v.assign(1, c);
VERIFY( ++v.begin() == v.end() );
v.assign(100, c);
VERIFY( (v.begin() + 100) == v.end() );
#endif
}
int main()
{
test01();
}
// Copyright (C) 2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++17" }
// 21.3.1.7 [string.ops] string operations
#include <string>
#include <testsuite_hooks.h>
void
test01()
{
std::string s;
char* p = s.data();
VERIFY( *p == '\0' );
s = "a string that is longer than a short string";
p = s.data();
VERIFY( p == &s.front() );
}
int
main()
{
test01();
}
// Copyright (C) 2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++17" }
// 21.3.1.7 [string.ops] string operations
#include <string>
#include <testsuite_hooks.h>
void
test01()
{
std::wstring s;
wchar_t* p = s.data();
VERIFY( *p == L'\0' );
s = L"a string that is longer than a short string";
p = s.data();
VERIFY( p == &s.front() );
}
int
main()
{
test01();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment