diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2016-07-13 11:08:37 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2016-07-13 11:08:37 +0000 |
commit | e0944692aad1036181435b0fdadf3f8ab818b325 (patch) | |
tree | 13cd8c4c8df5f3c9af5fdd00260d2e74accbc60d /libstdc++-v3/testsuite/21_strings/basic_string/operations/data | |
parent | f5ef8839e63d3a4061c62010fc4544f9f1b71536 (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.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@238291 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/21_strings/basic_string/operations/data')
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/operations/data/char/2.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc | 40 |
2 files changed, 80 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/char/2.cc new file mode 100644 index 00000000000..046780df410 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/char/2.cc @@ -0,0 +1,40 @@ +// 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(); +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc new file mode 100644 index 00000000000..d4a3206d3b2 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc @@ -0,0 +1,40 @@ +// 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(); +} |