diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1beefb131cc..7d3fd02a9c7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2011-11-07 Jonathan Wakely + + * include/bits/basic_string.h (basic_string::at): Move adjacent to other + overload. + (basic_string::pop_back): Define. + * include/debug/string (__gnu_debug::basic_string::pop_back): Likewise. + * include/ext/vstring.h (__versa_string::pop_back): Likewise. + * config/abi/pre/gnu.ver: Add new symbols. + * testsuite/21_strings/basic_string/modifiers/char/pop_back.cc: New. + * testsuite/21_strings/basic_string/modifiers/wchar_t/pop_back.cc: New. + * testsuite/21_strings/basic_string/range_access.cc: Split to ... + * testsuite/21_strings/basic_string/range_access/char/1.cc: Here and ... + * testsuite/21_strings/basic_string/range_access/wchar_t/1.cc: Here. + * testsuite/ext/vstring/modifiers/char/pop_back.cc: New. + * testsuite/ext/vstring/modifiers/wchar_t/pop_back.cc: New. + 2011-11-06 Jonathan Wakely * doc/xml/manual/backwards_compatibility.xml: Fix autoconf tests for diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index bb5ff9a3a20..2810c84dab5 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -225,9 +225,10 @@ GLIBCXX_3.4 { _ZNKSs[0-3][a-b]*; _ZNKSs[5-9][a-b]*; _ZNKSs[0-9][d-e]*; - _ZNKSs[0-9][g-z]*; + _ZNKSs[0-79][g-z]*; _ZNKSs[0-9][0-9][a-z]*; _ZNKSs4find*; + _ZNKSs8max_size*; _ZNKSs[a-z]*; _ZNKSs4_Rep12_M_is_leakedEv; _ZNKSs4_Rep12_M_is_sharedEv; @@ -286,10 +287,11 @@ GLIBCXX_3.4 { _ZNKSbIwSt11char_traitsIwESaIwEE[0-3][a-b]*; _ZNKSbIwSt11char_traitsIwESaIwEE[5-9][a-b]*; _ZNKSbIwSt11char_traitsIwESaIwEE[0-9][d-e]*; - _ZNKSbIwSt11char_traitsIwESaIwEE[0-9][g-z]*; + _ZNKSbIwSt11char_traitsIwESaIwEE[0-79][g-z]*; _ZNKSbIwSt11char_traitsIwESaIwEE[0-9][0-9][a-z]*; _ZNKSbIwSt11char_traitsIwESaIwEE[a-z]*; _ZNKSbIwSt11char_traitsIwESaIwEE4find*; + _ZNKSbIwSt11char_traitsIwESaIwEE8max_size*; _ZNKSbIwSt11char_traitsIwESaIwEE4_Rep12_M_is_leakedEv; _ZNKSbIwSt11char_traitsIwESaIwEE4_Rep12_M_is_sharedEv; _ZNKSbIwSt11char_traitsIwESaIwEE6_M_repEv; @@ -1302,6 +1304,11 @@ GLIBCXX_3.4.17 { _ZNSt14numeric_limitsInE*; _ZNSt14numeric_limitsIoE*; + # std::string::pop_back() + _ZNSs8pop_backEv; + # std::wstring::pop_back() + _ZNSbIwSt11char_traitsIwESaIwEE8pop_backEv; + } GLIBCXX_3.4.16; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 0edb8b2f8df..00f9bccd419 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -865,6 +865,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _M_data()[__n]; } + /** + * @brief Provides access to the data contained in the %string. + * @param __n The index of the character to access. + * @return Read/write reference to the character. + * @throw std::out_of_range If @a n is an invalid index. + * + * This function provides for safer data access. The parameter is + * first checked that it is in the range of the string. The function + * throws out_of_range if the check fails. Success results in + * unsharing the string. + */ + reference + at(size_type __n) + { + if (__n >= size()) + __throw_out_of_range(__N("basic_string::at")); + _M_leak(); + return _M_data()[__n]; + } + #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * Returns a read/write reference to the data at the first @@ -899,26 +919,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return operator[](this->size() - 1); } #endif - /** - * @brief Provides access to the data contained in the %string. - * @param __n The index of the character to access. - * @return Read/write reference to the character. - * @throw std::out_of_range If @a n is an invalid index. - * - * This function provides for safer data access. The parameter is - * first checked that it is in the range of the string. The function - * throws out_of_range if the check fails. Success results in - * unsharing the string. - */ - reference - at(size_type __n) - { - if (__n >= size()) - __throw_out_of_range(__N("basic_string::at")); - _M_leak(); - return _M_data()[__n]; - } - // Modifiers: /** * @brief Append a string to this string. @@ -1394,6 +1394,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION iterator erase(iterator __first, iterator __last); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Remove the last character. + * + * The string must be non-empty. + */ + void + pop_back() + { erase(size()-1, 1); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Replace characters with value from another string. * @param __pos Index of first character to replace. diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index 7856b240b86..6350f6de5e5 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -580,6 +580,16 @@ namespace __gnu_debug return iterator(__res, this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + pop_back() + { + __glibcxx_check_nonempty(); + _Base::pop_back(); + this->_M_invalidate_all(); + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str) { diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 5720daf3919..a613e364d3a 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -1140,6 +1140,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return iterator(this->_M_data() + __pos); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Remove the last character. + * + * The string must be non-empty. + */ + void + pop_back() + { this->_M_erase(size()-1, 1); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Replace characters with value from another string. * @param __pos Index of first character to replace. diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/char/pop_back.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/char/pop_back.cc new file mode 100644 index 00000000000..1f0f3d884fb --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/char/pop_back.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2011 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 +// . + +// 21.4.6.5 basic_string::pop_back +// { dg-options "-std=gnu++0x" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const std::string cstr("Badger"); + std::string str = cstr; + str.pop_back(); + VERIFY( str.size() == cstr.size() - 1 ); + + str += cstr.back(); + VERIFY( str == cstr ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/wchar_t/pop_back.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/wchar_t/pop_back.cc new file mode 100644 index 00000000000..fb5db8c1380 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/wchar_t/pop_back.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2011 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 +// . + +// 21.4.6.5 basic_string::pop_back +// { dg-options "-std=gnu++0x" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const std::wstring cstr(L"Badger"); + std::wstring str = cstr; + str.pop_back(); + VERIFY( str.size() == cstr.size() - 1 ); + + str += cstr.back(); + VERIFY( str == cstr ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc new file mode 100644 index 00000000000..458bf53e2c5 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010, 2011 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 Pred 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 +// . + +// 24.6.5, range access [iterator.range] + +#include + +void +test01() +{ + std::string s("Hello, World!"); + std::begin(s); + std::end(s); +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc similarity index 88% rename from libstdc++-v3/testsuite/21_strings/basic_string/range_access.cc rename to libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc index 1ce386cbe96..e300b092389 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/range_access.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2010 Free Software Foundation, Inc. +// Copyright (C) 2010. 2011 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 @@ -25,10 +25,6 @@ void test01() { - std::string s("Hello, World!"); - std::begin(s); - std::end(s); - #ifdef _GLIBCXX_USE_WCHAR_T std::wstring ws(L"Hello, World!"); std::begin(ws); diff --git a/libstdc++-v3/testsuite/ext/vstring/modifiers/char/pop_back.cc b/libstdc++-v3/testsuite/ext/vstring/modifiers/char/pop_back.cc new file mode 100644 index 00000000000..4dfa2f6fed8 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/vstring/modifiers/char/pop_back.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2011 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 +// . + +// 21.4.6.5 basic_string::pop_back +// { dg-options "-std=gnu++0x" } + +#include +#include + +template +int test01() +{ + bool test __attribute__((unused)) = true; + + const StrT cstr("Badger"); + StrT str = cstr; + str.pop_back(); + VERIFY( str.size() == cstr.size() - 1 ); + + str += cstr.back(); + VERIFY( str == cstr ); + + return test; +} + +int main() +{ + test01<__gnu_cxx::__sso_string>(); + test01<__gnu_cxx::__rc_string>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/vstring/modifiers/wchar_t/pop_back.cc b/libstdc++-v3/testsuite/ext/vstring/modifiers/wchar_t/pop_back.cc new file mode 100644 index 00000000000..ae607b61de3 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/vstring/modifiers/wchar_t/pop_back.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2011 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 +// . + +// 21.4.6.5 basic_string::pop_back +// { dg-options "-std=gnu++0x" } + +#include +#include + +template +int test01() +{ + bool test __attribute__((unused)) = true; + + const StrT cstr(L"Badger"); + StrT str = cstr; + str.pop_back(); + VERIFY( str.size() == cstr.size() - 1 ); + + str += cstr.back(); + VERIFY( str == cstr ); + + return test; +} + +int main() +{ + test01<__gnu_cxx::__wsso_string>(); + test01<__gnu_cxx::__wrc_string>(); + return 0; +}