OSDN Git Service

* include/bits/basic_string.h (basic_string::at): Move adjacent to other
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Nov 2011 00:06:23 +0000 (00:06 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Nov 2011 00:06:23 +0000 (00:06 +0000)
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.

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

libstdc++-v3/ChangeLog
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/debug/string
libstdc++-v3/include/ext/vstring.h
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/char/pop_back.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/wchar_t/pop_back.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc [moved from libstdc++-v3/testsuite/21_strings/basic_string/range_access.cc with 88% similarity]
libstdc++-v3/testsuite/ext/vstring/modifiers/char/pop_back.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/vstring/modifiers/wchar_t/pop_back.cc [new file with mode: 0644]

index 1beefb1..7d3fd02 100644 (file)
@@ -1,3 +1,19 @@
+2011-11-07  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       * 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  <jwakely.gcc@gmail.com>
 
        * doc/xml/manual/backwards_compatibility.xml: Fix autoconf tests for
index bb5ff9a..2810c84 100644 (file)
@@ -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.
index 0edb8b2..00f9bcc 100644 (file)
@@ -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.
index 7856b24..6350f6d 100644 (file)
@@ -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)
     {
index 5720daf..a613e36 100644 (file)
@@ -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 (file)
index 0000000..1f0f3d8
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 21.4.6.5 basic_string::pop_back
+// { dg-options "-std=gnu++0x" }
+
+#include <string>
+#include <testsuite_hooks.h>
+
+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 (file)
index 0000000..fb5db8c
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 21.4.6.5 basic_string::pop_back
+// { dg-options "-std=gnu++0x" }
+
+#include <string>
+#include <testsuite_hooks.h>
+
+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 (file)
index 0000000..458bf53
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 24.6.5, range access [iterator.range]
+
+#include <string>
+
+void
+test01()
+{
+  std::string s("Hello, World!");
+  std::begin(s);
+  std::end(s);
+}
@@ -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
 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 (file)
index 0000000..4dfa2f6
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 21.4.6.5 basic_string::pop_back
+// { dg-options "-std=gnu++0x" }
+
+#include <ext/vstring.h>
+#include <testsuite_hooks.h>
+
+template<typename StrT>
+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 (file)
index 0000000..ae607b6
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 21.4.6.5 basic_string::pop_back
+// { dg-options "-std=gnu++0x" }
+
+#include <ext/vstring.h>
+#include <testsuite_hooks.h>
+
+template<typename StrT>
+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;
+}