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
+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.
{
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);
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;
}