OSDN Git Service

2001-11-21 Paolo Carlini <pcarlini@unitus.it>
authorpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Nov 2001 22:04:53 +0000 (22:04 +0000)
committerpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Nov 2001 22:04:53 +0000 (22:04 +0000)
PR libstdc++/4548
* include/bits/basic_string.tcc (basic_string::reserve):  Never shrink
below the current size.
* testsuite/21_strings/capacity.cc (test02):  Add test.

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/capacity.cc

index 42a766a..deb1321 100644 (file)
@@ -1,3 +1,10 @@
+2001-11-21  Paolo Carlini  <pcarlini@unitus.it>
+
+       PR libstdc++/4548
+       * include/bits/basic_string.tcc (basic_string::reserve):  Never shrink
+       below the current size.
+       * testsuite/21_strings/capacity.cc (test02):  Add test.
+
 2001-11-19  Phil Edwards  <pme@gcc.gnu.org>
 
        * docs/doxygen/Intro.3:  More notes.
index 84ec0cf..d1dd1cb 100644 (file)
@@ -315,6 +315,9 @@ namespace std
         {
          if (__res > this->max_size())
            __throw_length_error("basic_string::reserve");
+         // Make sure we don't shrink below the current size
+         if (__res < this->size())
+           __res = this->size();
          allocator_type __a = get_allocator();
          _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
          _M_rep()->_M_dispose(__a);
index ed47e4e..8239f1b 100644 (file)
@@ -169,9 +169,30 @@ bool test01()
   return test;
 }
 
+// libstdc++/4548
+// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html
+bool test02()
+{
+  bool test = true;
+
+  std::string str01 = "twelve chars";
+  // str01 becomes shared
+  std::string str02 = str01;
+  str01.reserve(1);
+  VERIFY( str01.capacity() == 12 );
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+
+  return test;
+}
+
+
 int main()
 {
   test01();
+  test02();
 
   return 0;
 }