From: Paolo Carlini Date: Sun, 10 Jan 2010 13:38:47 +0000 (+0000) Subject: basic_string.h (basic_string<>:: basic_string(basic_string&&), [...]): Add. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=10154e0d52f3d0763967aacac4069efa985b9cb1;p=gcc.git basic_string.h (basic_string<>:: basic_string(basic_string&&), [...]): Add. 2010-01-10 Paolo Carlini * 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 --- 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 + + * 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 * 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. @@ -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 - 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 +// . + +// 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 +#include +#include + +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 +// . + +// 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 +#include +#include + +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 +// . + +// 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 +#include +#include + +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 +// . + +// 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 +#include +#include + +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 +// . + +// 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 +#include +#include + +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