PR libstdc++/84087 add default arguments to basic_string members (LWG 2268)

This change was a DR against C++11 and so should have been implemented
years ago.

	PR libstdc++/84087 LWG DR 2268 basic_string default arguments
	* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI=1]
	(append(const basic_string&, size_type, size_type)
	(assign(const basic_string&, size_type, size_type)
	(insert(size_type, const basic_string&, size_type, size_type)
	(replace(size_type,size_type,const basic_string&,size_type,size_type)
	(compare(size_type,size_type,constbasic_string&,size_type,size_type)):
	Add default arguments (LWG 2268).
	[_GLIBCXX_USE_CXX11_ABI=0]
	(append(const basic_string&, size_type, size_type)
	(assign(const basic_string&, size_type, size_type)
	(insert(size_type, const basic_string&, size_type, size_type)
	(replace(size_type,size_type,const basic_string&,size_type,size_type)
	(compare(size_type,size_type,constbasic_string&,size_type,size_type)):
	Likewise.
	* testsuite/21_strings/basic_string/dr2268.cc: New test.

From-SVN: r259895
This commit is contained in:
Jonathan Wakely 2018-05-03 16:01:20 +01:00 committed by Jonathan Wakely
parent d49b342694
commit 852ee53c27
3 changed files with 72 additions and 10 deletions

View File

@ -1,5 +1,22 @@
2018-05-03 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/84087 LWG DR 2268 basic_string default arguments
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI=1]
(append(const basic_string&, size_type, size_type)
(assign(const basic_string&, size_type, size_type)
(insert(size_type, const basic_string&, size_type, size_type)
(replace(size_type,size_type,const basic_string&,size_type,size_type)
(compare(size_type,size_type,constbasic_string&,size_type,size_type)):
Add default arguments (LWG 2268).
[_GLIBCXX_USE_CXX11_ABI=0]
(append(const basic_string&, size_type, size_type)
(assign(const basic_string&, size_type, size_type)
(insert(size_type, const basic_string&, size_type, size_type)
(replace(size_type,size_type,const basic_string&,size_type,size_type)
(compare(size_type,size_type,constbasic_string&,size_type,size_type)):
Likewise.
* testsuite/21_strings/basic_string/dr2268.cc: New test.
PR libstdc++/84535
* include/std/thread (thread::__not_same): New SFINAE helper.
(thread::thread(_Callable&&, _Args&&...)): Add SFINAE constraint that

View File

@ -1216,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* remainder of @a __str is appended.
*/
basic_string&
append(const basic_string& __str, size_type __pos, size_type __n)
append(const basic_string& __str, size_type __pos, size_type __n = npos)
{ return _M_append(__str._M_data()
+ __str._M_check(__pos, "basic_string::append"),
__str._M_limit(__pos, __n)); }
@ -1381,7 +1381,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* __str, the remainder of @a __str is used.
*/
basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n)
assign(const basic_string& __str, size_type __pos, size_type __n = npos)
{ return _M_replace(size_type(0), this->size(), __str._M_data()
+ __str._M_check(__pos, "basic_string::assign"),
__str._M_limit(__pos, __n)); }
@ -1633,7 +1633,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
basic_string&
insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n)
size_type __pos2, size_type __n = npos)
{ return this->replace(__pos1, size_type(0), __str._M_data()
+ __str._M_check(__pos2, "basic_string::insert"),
__str._M_limit(__pos2, __n)); }
@ -1881,7 +1881,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2)
size_type __pos2, size_type __n2 = npos)
{ return this->replace(__pos1, __n1, __str._M_data()
+ __str._M_check(__pos2, "basic_string::replace"),
__str._M_limit(__pos2, __n2)); }
@ -2941,7 +2941,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2) const;
size_type __pos2, size_type __n2 = npos) const;
/**
* @brief Compare to a C string.
@ -4135,7 +4135,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
* remainder of @a __str is appended.
*/
basic_string&
append(const basic_string& __str, size_type __pos, size_type __n);
append(const basic_string& __str, size_type __pos, size_type __n = npos);
/**
* @brief Append a C substring.
@ -4280,7 +4280,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
* __str, the remainder of @a __str is used.
*/
basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n)
assign(const basic_string& __str, size_type __pos, size_type __n = npos)
{ return this->assign(__str._M_data()
+ __str._M_check(__pos, "basic_string::assign"),
__str._M_limit(__pos, __n)); }
@ -4468,7 +4468,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
basic_string&
insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n)
size_type __pos2, size_type __n = npos)
{ return this->insert(__pos1, __str._M_data()
+ __str._M_check(__pos2, "basic_string::insert"),
__str._M_limit(__pos2, __n)); }
@ -4703,7 +4703,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2)
size_type __pos2, size_type __n2 = npos)
{ return this->replace(__pos1, __n1, __str._M_data()
+ __str._M_check(__pos2, "basic_string::replace"),
__str._M_limit(__pos2, __n2)); }
@ -5779,7 +5779,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2) const;
size_type __pos2, size_type __n2 = npos) const;
/**
* @brief Compare to a C string.

View File

@ -0,0 +1,45 @@
// Copyright (C) 2018 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-do run { target c++11 } }
#include <string>
#include <testsuite_hooks.h>
void
test01()
{
// PR libstdc++/84087
std::string s0 = "string";
std::string s;
s.append(s0, 2);
VERIFY( s == "ring" );
s.assign(s0, 3);
VERIFY( s == "ing" );
s.insert(2, s0, 4);
VERIFY( s == "inngg" );
s.replace(2, 3, s0, 2);
VERIFY( s == "inring" );
VERIFY( s.compare(2, 4, s0, 2) == 0 );
}
int
main()
{
test01();
}