basic_string.h (basic_string<>:: basic_string(basic_string&&), [...]): Add.
authorPaolo Carlini <paolo@gcc.gnu.org>
Sun, 10 Jan 2010 13:38:47 +0000 (13:38 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 10 Jan 2010 13:38:47 +0000 (13:38 +0000)
2010-01-10  Paolo Carlini  <paolo.carlini@oracle.com>

* include/bits/basic_string.h (basic_string<>::
basic_string(basic_string&&), operator=(basic_string&&),
assign(basic_string&&)): Add.
* config/abi/pre/gnu.ver: Export new symbols.
* include/ext/vstring.h (__versa_string<>::assign(__versa_string&&)):
Add.
(operator=(__versa_string&&)): Don't call clear unnecessarily.
* include/ext/rc_string_base.h (__rc_string_base<>::
__rc_string_base(__rc_string_base&&)): Simplify a tad.
* testsuite/21_strings/basic_string/cons/char/moveable.cc: New.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc: Likewise.
* testsuite/ext/vstring/assign/move_assign.cc: Likewise.
* testsuite/21_strings/basic_string/assign/char/move_assign.cc:
Likewise.
* testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc:
Likewise.

From-SVN: r155788

libstdc++-v3/ChangeLog
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/ext/rc_string_base.h
libstdc++-v3/include/ext/vstring.h
libstdc++-v3/testsuite/21_strings/basic_string/assign/char/move_assign.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/vstring/assign/move_assign.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc

index a45c73539b2a5804daff1bd27587d89131f690dd..349280e29e8e1c7c3b99c9ae1898b39cf2b0ba05 100644 (file)
@@ -1,14 +1,33 @@
+2010-01-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/bits/basic_string.h (basic_string<>::
+       basic_string(basic_string&&), operator=(basic_string&&),
+       assign(basic_string&&)): Add.
+       * config/abi/pre/gnu.ver: Export new symbols.
+       * include/ext/vstring.h (__versa_string<>::assign(__versa_string&&)):
+       Add.
+       (operator=(__versa_string&&)): Don't call clear unnecessarily.
+       * include/ext/rc_string_base.h (__rc_string_base<>::
+       __rc_string_base(__rc_string_base&&)): Simplify a tad.
+       * testsuite/21_strings/basic_string/cons/char/moveable.cc: New.
+       * testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc: Likewise.
+       * testsuite/ext/vstring/assign/move_assign.cc: Likewise.
+       * testsuite/21_strings/basic_string/assign/char/move_assign.cc:
+       Likewise.
+       * testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc:
+       Likewise.
+
 2010-01-10  Silvius Rus  <rus@google.com>
 
        * configure.ac: Add detection of execinfo.h.
-       * configure: Same.
-       * config.h.in: Same.
+       * configure: Regenerate.
+       * config.h.in: Likewise.
        * doc/xml/manual/profile_mode.xml: Add list_to_slist manual.
        Also, correct user interface mistakes.
-       * include/Makefile.in: Add references to new include files.
        * include/Makefile.am: Add references to new include files.
+       * include/Makefile.in: Regenerate.
        * include/backward/hash_map: Remove profile include.
-       * include/backward/hash_set: Remove profile include.
+       * include/backward/hash_set: Likewise.
        * include/profile/hashtable.h: Delete file.
        * include/profile/iterator_tracker.h: New file.
        * include/profile/vector: Add instrumentation for tracked iterator.
index 142aa089827913451eb6f41f7e32c74b9a27f7d6..c6ad78abf92bdf81809b25a0cc362f6e5ff61308 100644 (file)
@@ -1098,6 +1098,15 @@ GLIBCXX_3.4.14 {
     _ZNSs13shrink_to_fitEv;
     _ZNSbIwSt11char_traitsIwESaIwEE13shrink_to_fitEv;
 
+    # string|wstring move contructor, move assignment operator and
+    # move assign.
+    _ZNSsC1EOSs;
+    _ZNSbIwSt11char_traitsIwESaIwEEC1EOS2_;
+    _ZNSsaSEOSs;
+    _ZNSbIwSt11char_traitsIwESaIwEEC1EOS2_;
+    _ZNSs6assignEOSs;
+    _ZNSbIwSt11char_traitsIwESaIwEE6assignEOS2_;
+
     _ZSt25__throw_bad_function_callv;
 
     # std::time_get::_M_extract_wday_or_month
index e82b8900111a1ff16d439aa4e6f1592ebfe254e7..a549cf76063fa8036edfe1338c3f8e2d49b93f88 100644 (file)
@@ -1,7 +1,7 @@
 // Components for manipulating sequences of characters -*- C++ -*-
 
 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2008, 2009
+// 2006, 2007, 2008, 2009, 2010
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -419,8 +419,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       /**
        *  @brief  Default constructor creates an empty string.
        */
-      inline
-      basic_string();
+      basic_string()
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
+      : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
+#else
+      : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
+#endif
 
       /**
        *  @brief  Construct an empty string using allocator @a a.
@@ -478,6 +482,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Move construct string.
+       *  @param  str  Source string.
+       *
+       *  The newly-created string contains the exact contents of @a str.
+       *  @a str is a valid, but unspecified string.
+       **/
+      basic_string(basic_string&& __str)
+      : _M_dataplus(__str._M_dataplus)
+      {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING  
+       __str._M_data(_S_empty_rep()._M_refdata());
+#else
+       __str._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
+#endif
+      }
+
       /**
        *  @brief  Construct string from an initializer list.
        *  @param  l  std::initializer_list of characters.
@@ -533,6 +554,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Move assign the value of @a str to this string.
+       *  @param  str  Source string.
+       *
+       *  The contents of @a str are moved into this string (without copying).
+       *  @a str is a valid, but unspecified string.
+       **/
+      basic_string&
+      operator=(basic_string&& __str)
+      {
+       // NB: DR 1204.
+       this->swap(__str);
+       return *this;
+      }
+
       /**
        *  @brief  Set value to string constructed from initializer list.
        *  @param  l  std::initializer_list.
@@ -976,6 +1012,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       basic_string&
       assign(const basic_string& __str);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Set value to contents of another string.
+       *  @param  str  Source string to use.
+       *  @return  Reference to this string.
+       *
+       *  This function sets this string to the exact contents of @a str.
+       *  @a str is a valid, but unspecified string.
+       */
+      basic_string&
+      assign(basic_string&& __str)
+      {
+       this->swap(__str);
+       return *this;
+      }
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
       /**
        *  @brief  Set value to a substring of a string.
        *  @param str  The string to use.
@@ -2196,15 +2249,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              size_type __n2) const;
   };
 
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    inline basic_string<_CharT, _Traits, _Alloc>::
-    basic_string()
-#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
-    : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
-#else
-    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
-#endif
-
   // operator+
   /**
    *  @brief  Concatenate two strings.
index d1b516274b3f65980c1e304b22a5e7f5a85f9686..52a481d1ae5d3bf4056fd42f396b83a08408b160 100644 (file)
@@ -1,6 +1,7 @@
 // Reference-counted versatile string base -*- C++ -*-
 
-// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
+// 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
@@ -307,7 +308,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       __rc_string_base(__rc_string_base&& __rcs)
-      : _M_dataplus(__rcs._M_get_allocator(), __rcs._M_data())
+      : _M_dataplus(__rcs._M_dataplus)
       { __rcs._M_data(_S_empty_rep._M_refcopy()); }
 #endif
 
index bc3d829d8e159381633bf3dd07a5787a3cfa19d8..05307771e8f460cf2c78f9f75b4192312ef715de 100644 (file)
@@ -261,8 +261,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
       operator=(__versa_string&& __str)
       {
        // NB: DR 1204.
-       // NB: DR 675.
-       this->clear();
        this->swap(__str);
        return *this;
       }
@@ -784,6 +782,23 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
        return *this;
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Set value to contents of another string.
+       *  @param  __str  Source string to use.
+       *  @return  Reference to this string.
+       *
+       *  This function sets this string to the exact contents of @a __str.
+       *  @a __str is a valid, but unspecified string.
+       */
+      __versa_string&
+      assign(__versa_string&& __str)
+      {
+       this->swap(__str);
+       return *this;
+      }
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
       /**
        *  @brief  Set value to a substring of a string.
        *  @param __str  The string to use.
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/move_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/move_assign.cc
new file mode 100644 (file)
index 0000000..064a8cb
--- /dev/null
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2010 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/>.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on string (via swap). If the implementation changes
+// this test may begin to fail.
+
+#include <string>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::string a, b;
+  a.push_back('1');
+  b.assign(std::move(a));
+  VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc
new file mode 100644 (file)
index 0000000..7aa48d8
--- /dev/null
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2010 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/>.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on string (via swap). If the implementation changes
+// this test may begin to fail.
+
+#include <string>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::wstring a, b;
+  a.push_back(L'1');
+  b.assign(std::move(a));
+  VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable.cc
new file mode 100644 (file)
index 0000000..58b1e44
--- /dev/null
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2010 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/>.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on string (via swap). If the implementation changed
+// this test may begin to fail.
+
+#include <string>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::string a, b;
+  a.push_back('1');
+  b = std::move(a);
+  VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 );
+
+  std::string c(std::move(b));
+  VERIFY( c.size() == 1 && c[0] == '1' );
+  VERIFY( b.size() == 0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc
new file mode 100644 (file)
index 0000000..67a0fbe
--- /dev/null
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2010 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/>.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on string (via swap). If the implementation changed
+// this test may begin to fail.
+
+#include <string>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::wstring a, b;
+  a.push_back(L'1');
+  b = std::move(a);
+  VERIFY( b.size() == 1 && b[0] == L'1' && a.size() == 0 );
+
+  std::wstring c(std::move(b));
+  VERIFY( c.size() == 1 && c[0] == L'1' );
+  VERIFY( b.size() == 0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/vstring/assign/move_assign.cc b/libstdc++-v3/testsuite/ext/vstring/assign/move_assign.cc
new file mode 100644 (file)
index 0000000..3f9e055
--- /dev/null
@@ -0,0 +1,54 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2010 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/>.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on vstring (via swap). If the implementation changes
+// this test may begin to fail.
+
+#include <ext/vstring.h>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  __gnu_cxx::__sso_string a, b;
+  a.push_back('1');
+  b.assign(std::move(a));
+  VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 );
+}
+
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  __gnu_cxx::__rc_string a, b;
+  a.push_back('1');
+  b.assign(std::move(a));
+  VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 );
+}
+
+int main()
+{
+  test01();
+  test02();
+  return 0;
+}
index 8248636854398328510ab9649107a7ccc51f586b..b2572b2ddae2d3489f0c2f0bbce798e603365140 100644 (file)
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++0x" }
 // { dg-require-string-conversions "" }
 
-// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010 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
@@ -20,7 +20,7 @@
 
 
 // NOTE: This makes use of the fact that we know how moveable
-// is implemented on deque (via swap). If the implementation changed
+// is implemented on vstring (via swap). If the implementation changes
 // this test may begin to fail.
 
 #include <ext/vstring.h>