summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-01-10 13:38:47 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-01-10 13:38:47 +0000
commitc20b51510a37cb725712b58c0dc7baa5d346762d (patch)
tree341c6de90f33bc6defb43add0ff9f7e9c55d9ee2 /libstdc++-v3
parenta2c5e3fd5d25dddec17e1029837962336aba8a0a (diff)
downloadgcc-c20b51510a37cb725712b58c0dc7baa5d346762d.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155788 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog27
-rw-r--r--libstdc++-v3/config/abi/pre/gnu.ver9
-rw-r--r--libstdc++-v3/include/bits/basic_string.h68
-rw-r--r--libstdc++-v3/include/ext/rc_string_base.h5
-rw-r--r--libstdc++-v3/include/ext/vstring.h19
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/assign/char/move_assign.cc43
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc43
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable.cc47
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc47
-rw-r--r--libstdc++-v3/testsuite/ext/vstring/assign/move_assign.cc54
-rw-r--r--libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc4
11 files changed, 344 insertions, 22 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a45c73539b2..349280e29e8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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.
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 142aa089827..c6ad78abf92 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -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
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index e82b8900111..a549cf76063 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -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.
@@ -479,6 +483,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
#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.
* @param a Allocator to use (default is default allocator).
@@ -534,6 +555,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.
diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h
index d1b516274b3..52a481d1ae5 100644
--- a/libstdc++-v3/include/ext/rc_string_base.h
+++ b/libstdc++-v3/include/ext/rc_string_base.h
@@ -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
diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h
index bc3d829d8e1..05307771e8f 100644
--- a/libstdc++-v3/include/ext/vstring.h
+++ b/libstdc++-v3/include/ext/vstring.h
@@ -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
index 00000000000..064a8cb7d81
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/char/move_assign.cc
@@ -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
index 00000000000..7aa48d814ee
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/assign/wchar_t/move_assign.cc
@@ -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
index 00000000000..58b1e446158
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable.cc
@@ -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
index 00000000000..67a0fbed781
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc
@@ -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
index 00000000000..3f9e055b8da
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/vstring/assign/move_assign.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc b/libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc
index 82486368543..b2572b2ddae 100644
--- a/libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc
+++ b/libstdc++-v3/testsuite/ext/vstring/cons/moveable.cc
@@ -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>