aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-05-03 16:01:20 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2018-05-03 16:01:20 +0100
commit852ee53c2775b43fef0bdba08c160ea95c1c7245 (patch)
tree3c558d45cbbbce1ee2ab96830fe036b2d53799fd /libstdc++-v3
parentd49b3426947aa1064d8d224619da66daaf4bfb8a (diff)
downloadgcc-852ee53c2775b43fef0bdba08c160ea95c1c7245.zip
gcc-852ee53c2775b43fef0bdba08c160ea95c1c7245.tar.gz
gcc-852ee53c2775b43fef0bdba08c160ea95c1c7245.tar.bz2
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog17
-rw-r--r--libstdc++-v3/include/bits/basic_string.h20
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/dr2268.cc45
3 files changed, 72 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4176044..3b12844 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 3e8310e..5bffa1c 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 0000000..3ad6860
--- /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
+// <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();
+}