From cf3c455b106cf5e122575c8fbb0c72b7612c50c1 Mon Sep 17 00:00:00 2001 From: redi Date: Thu, 3 May 2018 15:01:20 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259895 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 17 ++++++++ libstdc++-v3/include/bits/basic_string.h | 20 +++++----- .../testsuite/21_strings/basic_string/dr2268.cc | 45 ++++++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/dr2268.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 41760444d59..3b12844d02d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,22 @@ 2018-05-03 Jonathan Wakely + 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 diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 3e8310e762c..5bffa1c72a1 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -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. diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/dr2268.cc b/libstdc++-v3/testsuite/21_strings/basic_string/dr2268.cc new file mode 100644 index 00000000000..3ad6860d81f --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/dr2268.cc @@ -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 +// . + +// { dg-do run { target c++11 } } + +#include +#include + +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(); +} -- 2.11.4.GIT