]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add new std::basic_string constructor (LWG 2583)
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 Aug 2016 10:41:37 +0000 (10:41 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 Aug 2016 10:41:37 +0000 (10:41 +0000)
* config/abi/pre/gnu.ver (GLIBCXX_3.4, GLIBCXX_3.4.21): Use more
precise patterns for basic_string constructors.
(GLIBCXX_3.4.23): Export new constructors.
* doc/xml/manual/intro.xml: Document LWG 2583 status.
* doc/html/*: Regenerate.
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
(basic_string(const basic_string&, size_type, const Alloc&)): Add
new constructor for LWG 2583.
(basic_string(const basic_string&, size_type, size_type)): Remove
default argument.
[!_GLIBCXX_USE_CXX11_ABI]: Likewise.
* include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]: Define it.
* testsuite/21_strings/basic_string/cons/char/8.cc: New test.
* testsuite/21_strings/basic_string/cons/wchar_t/8.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239773 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/doc/html/manual/bugs.html
libstdc++-v3/doc/xml/manual/intro.xml
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/8.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/8.cc [new file with mode: 0644]

index 0d7e8bf7f594e7438e7a5dbfc10a9fa348981f40..8b552b08cfb9cf12ff27bbbc7987d09bd6c27620 100644 (file)
@@ -1,3 +1,20 @@
+2016-08-26  Jonathan Wakely  <jwakely@redhat.com>
+
+       * config/abi/pre/gnu.ver (GLIBCXX_3.4, GLIBCXX_3.4.21): Use more
+       precise patterns for basic_string constructors.
+       (GLIBCXX_3.4.23): Export new constructors.
+       * doc/xml/manual/intro.xml: Document LWG 2583 status.
+       * doc/html/*: Regenerate.
+       * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
+       (basic_string(const basic_string&, size_type, const Alloc&)): Add
+       new constructor for LWG 2583.
+       (basic_string(const basic_string&, size_type, size_type)): Remove
+       default argument.
+       [!_GLIBCXX_USE_CXX11_ABI]: Likewise.
+       * include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]: Define it.
+       * testsuite/21_strings/basic_string/cons/char/8.cc: New test.
+       * testsuite/21_strings/basic_string/cons/wchar_t/8.cc: New test.
+
 2016-08-24  Aditya Kumar  <hiraditya@msn.com>
 
        * include/bits/algorithmfwd.h: Remove trailing whitespace.
index f51c6f961b08728bc846e9a44effa5173239306d..0ab4bb10b35293f5a42513a1b08b4587919f1da9 100644 (file)
@@ -206,7 +206,14 @@ GLIBCXX_3.4 {
     # std::string
     # 'y' here and below represents 'unsigned long long'
     # where it is used for size_type on LLP64 platforms.
-    _ZNSsC[12][EI][PRjmvyN]*;
+    _ZNSsC[12]EPKc*;
+    _ZNSsC[12]ERKSaIcE;
+    _ZNSsC[12]ERKSs;
+#   _ZNSsC[12]ERKSs[jmy]RKSaIcE;
+    _ZNSsC[12]ERKSs[jmy][jmy]*;
+    _ZNSsC[12]E[jmy]cRKSaIcE;
+    _ZNSsC[12]Ev;
+    _ZNSsC[12]I[PN]*;
     _ZNSsD*;
     _ZNSs[0-58-9]a*;
     _ZNSs5beginEv;
@@ -267,7 +274,13 @@ GLIBCXX_3.4 {
     _ZNKSs4copyEPc[jmy][jmy];
 
     # std::wstring
-    _ZNSbIwSt11char_traitsIwESaIwEEC[12][EI][PRjmvyN]*;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]EPKw*;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS[12]_;
+#   _ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_mRKS1_;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_[jmy][jmy]*;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]E[jmy]wRKS1_;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]Ev;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]I[PN]*;
     _ZNSbIwSt11char_traitsIwESaIwEED*;
     _ZNSbIwSt11char_traitsIwESaIwEE[0-58-9]a*;
     _ZNSbIwSt11char_traitsIwESaIwEE5beginEv;
@@ -1683,7 +1696,17 @@ GLIBCXX_3.4.21 {
     _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_M*;
     _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE1[3-9]*;
     _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[2-9]*;
-    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[CDaip]*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EOS4_*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EPK*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS[34]_;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_RKS3_;
+#   _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy]RKS3_;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy][jmy]*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ESt16*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[jmy][cw]RKS3_;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]I[PN]*;
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[Daip]*;
     _ZNKSt7__cxx1112basic_string*;
 
     # operator+ for ABI-tagged std::basic_string
@@ -1919,6 +1942,11 @@ GLIBCXX_3.4.23 {
     # basic_string<C, T, A>::_Alloc_hider::_Alloc_hider(C*, A&&)
     _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_Alloc_hiderC[12]EP[cw]OS3_;
 
+    # basic_string<C, T, A>::basic_string(const basic_string&, size_type, const A&)
+    _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy]RKS3_;
+    _ZNSsC[12]ERKSs[jmy]RKSaIcE;
+    _ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_mRKS1_;
+
 } GLIBCXX_3.4.22;
 
 # Symbols in the support library (libsupc++) have their own tag.
index c078debaf532020092601ecbc8b1ca606f54c9f7..14ba1d2506ae758bf477ea0bfa813e2cc0f70972 100644 (file)
        <span class="emphasis"><em><code class="code">allocator_traits::max_size()</code> default behavior is incorrect
        </em></span>
     </span></dt><dd><p>Divide by the object type.
+    </p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2583" target="_top">2583</a>:
+       <span class="emphasis"><em>There is no way to supply an allocator for <code class="code"> basic_string(str, pos)</code>
+       </em></span>
+    </span></dt><dd><p>Add new constructor
     </p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2684" target="_top">2684</a>:
        <span class="emphasis"><em><code class="code">priority_queue</code> lacking comparator typedef
        </em></span>
index ea4d1c520961339ce1406b18217a3053ded971ea..d02306edbf67be8b7c6380c04219a387d03f38ef 100644 (file)
@@ -1058,6 +1058,13 @@ requirements of the license of GCC.
     <listitem><para>Divide by the object type.
     </para></listitem></varlistentry>
 
+    <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2583">2583</link>:
+       <emphasis>There is no way to supply an allocator for <code> basic_string(str, pos)</code>
+       </emphasis>
+    </term>
+    <listitem><para>Add new constructor
+    </para></listitem></varlistentry>
+
     <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2684">2684</link>:
        <emphasis><code>priority_queue</code> lacking comparator typedef
        </emphasis>
index 68cfc994de0cf9693e2fbb285e1ce0802559094f..e823f132d4eecb5cbfcceb7b3f7249fca10cde6c 100644 (file)
@@ -417,16 +417,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
                    _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
       { _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
 
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 2583. no way to supply an allocator for basic_string(str, pos)
       /**
        *  @brief  Construct string as copy of a substring.
        *  @param  __str  Source string.
        *  @param  __pos  Index of first character to copy from.
-       *  @param  __n  Number of characters to copy (default remainder).
+       *  @param  __a  Allocator to use.
+       */
+      basic_string(const basic_string& __str, size_type __pos,
+                  const _Alloc& __a = _Alloc())
+      : _M_dataplus(_M_local_data(), __a)
+      {
+       const _CharT* __start = __str._M_data()
+         + __str._M_check(__pos, "basic_string::basic_string");
+       _M_construct(__start, __start + __str._M_limit(__pos, npos));
+      }
+
+      /**
+       *  @brief  Construct string as copy of a substring.
+       *  @param  __str  Source string.
+       *  @param  __pos  Index of first character to copy from.
+       *  @param  __n  Number of characters to copy.
        */
-      // _GLIBCXX_RESOLVE_LIB_DEFECTS
-      // 2402. [this constructor] shouldn't use Allocator()
       basic_string(const basic_string& __str, size_type __pos,
-                  size_type __n = npos)
+                  size_type __n)
       : _M_dataplus(_M_local_data())
       {
        const _CharT* __start = __str._M_data()
@@ -438,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        *  @brief  Construct string as copy of a substring.
        *  @param  __str  Source string.
        *  @param  __pos  Index of first character to copy from.
-       *  @param  __n  Number of characters to copy (default remainder).
+       *  @param  __n  Number of characters to copy.
        *  @param  __a  Allocator to use.
        */
       basic_string(const basic_string& __str, size_type __pos,
@@ -3305,14 +3320,26 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *  @param  __str  Source string.
        */
       basic_string(const basic_string& __str);
+
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 2583. no way to supply an allocator for basic_string(str, pos)
       /**
        *  @brief  Construct string as copy of a substring.
        *  @param  __str  Source string.
        *  @param  __pos  Index of first character to copy from.
-       *  @param  __n  Number of characters to copy (default remainder).
+       *  @param  __a  Allocator to use.
+       */
+      basic_string(const basic_string& __str, size_type __pos,
+                  const _Alloc& __a = _Alloc());
+
+      /**
+       *  @brief  Construct string as copy of a substring.
+       *  @param  __str  Source string.
+       *  @param  __pos  Index of first character to copy from.
+       *  @param  __n  Number of characters to copy.
        */
       basic_string(const basic_string& __str, size_type __pos,
-                  size_type __n = npos);
+                  size_type __n);
       /**
        *  @brief  Construct string as copy of a substring.
        *  @param  __str  Source string.
index 0560b466d73cfd1b23a5c9d1518300f9af6cb2c4..0080d2b0e2f95bc62b7c34d2c9f0aff1d1952e8d 100644 (file)
@@ -619,6 +619,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
     { }
 
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    basic_string<_CharT, _Traits, _Alloc>::
+    basic_string(const basic_string& __str, size_type __pos, const _Alloc& __a)
+    : _M_dataplus(_S_construct(__str._M_data()
+                              + __str._M_check(__pos,
+                                               "basic_string::basic_string"),
+                              __str._M_data() + __str._M_limit(__pos, npos)
+                              + __pos, __a), __a)
+    { }
+
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>::
     basic_string(const basic_string& __str, size_type __pos, size_type __n)
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/8.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/8.cc
new file mode 100644 (file)
index 0000000..6534f76
--- /dev/null
@@ -0,0 +1,70 @@
+// 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-do run { target c++11 } }
+
+#include <string>
+#include <testsuite_hooks.h>
+
+template<typename... Args>
+std::size_t
+construct(Args&&... args)
+{
+  return std::string( std::forward<Args>(args)... ).length();
+}
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  using string = std::string;
+  using list = std::initializer_list<string::value_type>;
+
+  const std::string lvalue = "lvalue";
+  std::allocator<char> alloc;
+
+  // test all valid combinations of arguments:
+  VERIFY( construct( ) == 0 );
+  VERIFY( construct( alloc ) == 0 );
+  VERIFY( construct( lvalue ) == 6 );
+  VERIFY( construct( string{"rvalue"} ) == 6 );
+  VERIFY( construct( lvalue, 2 ) == 4 );
+  VERIFY( construct( lvalue, 2, alloc ) == 4 );
+  VERIFY( construct( lvalue, 2, 3 ) == 3 );
+  VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
+  VERIFY( construct( "C string", 4 ) == 4 );
+  VERIFY( construct( "C string", 4, alloc ) == 4 );
+  VERIFY( construct( "C string" ) == 8 );
+  VERIFY( construct( "C string and alloc", alloc ) == 18 );
+  VERIFY( construct( 5, ' ' ) == 5 );
+  VERIFY( construct( 5, ' ', alloc ) == 5 );
+  VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
+  VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
+  VERIFY( construct( list{ 'l' , 'i' , 's', 't' } ) == 4 );
+  VERIFY( construct( list{ 'l', 'i', 's', 't' }, alloc ) == 4 );
+#if _GLIBCXX_USE_CXX11_ABI
+  VERIFY( construct( lvalue, alloc ) == 6 );
+  VERIFY( construct( string{"rvalue"}, alloc ) == 6 );
+#endif
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/8.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/8.cc
new file mode 100644 (file)
index 0000000..9152ad9
--- /dev/null
@@ -0,0 +1,70 @@
+// 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-do run { target c++11 } }
+
+#include <string>
+#include <testsuite_hooks.h>
+
+template<typename... Args>
+std::size_t
+construct(Args&&... args)
+{
+  return std::wstring( std::forward<Args>(args)... ).length();
+}
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  using string = std::wstring;
+  using list = std::initializer_list<string::value_type>;
+
+  const std::wstring lvalue = L"lvalue";
+  std::allocator<char> alloc;
+
+  // test all valid combinations of arguments:
+  VERIFY( construct( ) == 0 );
+  VERIFY( construct( alloc ) == 0 );
+  VERIFY( construct( lvalue ) == 6 );
+  VERIFY( construct( string{L"rvalue"} ) == 6 );
+  VERIFY( construct( lvalue, 2 ) == 4 );
+  VERIFY( construct( lvalue, 2, alloc ) == 4 );
+  VERIFY( construct( lvalue, 2, 3 ) == 3 );
+  VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
+  VERIFY( construct( L"C string", 4 ) == 4 );
+  VERIFY( construct( L"C string", 4, alloc ) == 4 );
+  VERIFY( construct( L"C string" ) == 8 );
+  VERIFY( construct( L"C string and alloc", alloc ) == 18 );
+  VERIFY( construct( 5, L' ' ) == 5 );
+  VERIFY( construct( 5, L' ', alloc ) == 5 );
+  VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
+  VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
+  VERIFY( construct( list{ L'l' , L'i' , L's', L't' } ) == 4 );
+  VERIFY( construct( list{ L'l', L'i', L's', L't' }, alloc ) == 4 );
+#if _GLIBCXX_USE_CXX11_ABI
+  VERIFY( construct( lvalue, alloc ) == 6 );
+  VERIFY( construct( string{L"rvalue"}, alloc ) == 6 );
+#endif
+}
+
+int
+main()
+{
+  test01();
+}