PR libstdc++/29134 (ext/vstring bits)
* include/ext/sso_string_base.h (__sso_string_base<>::_S_max_size):
Remove.
(__sso_string_base<>::_M_max_size): Use allocator' max_size.
(__sso_string_base<>::_M_create): Adjust.
* include/ext/vstring.h: Minor comment tweak.
* testsuite/ext/vstring/capacity/29134.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117109
138bc75d-0d04-0410-961f-
82ee72b054a4
+2006-09-21 Paolo Carlini <pcarlini@suse.de>
+
+ PR libstdc++/29134 (ext/vstring bits)
+ * include/ext/sso_string_base.h (__sso_string_base<>::_S_max_size):
+ Remove.
+ (__sso_string_base<>::_M_max_size): Use allocator' max_size.
+ (__sso_string_base<>::_M_create): Adjust.
+ * include/ext/vstring.h: Minor comment tweak.
+ * testsuite/ext/vstring/capacity/29134.cc: New.
+
2006-09-20 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/29134
typedef typename _CharT_alloc_type::size_type size_type;
private:
- // The maximum number of individual char_type elements of an
- // individual string is determined by _S_max_size. This is the
- // value that will be returned by max_size(). (Whereas npos
- // is the maximum number of bytes the allocator can allocate.)
- // If one was to divvy up the theoretical largest size string,
- // with a terminating character and m _CharT elements, it'd
- // look like this:
- // npos = m * sizeof(_CharT) + sizeof(_CharT)
- // Solving for m:
- // m = npos / sizeof(_CharT) - 1
- // In addition, this implementation halfs this amount.
- enum { _S_max_size = (((static_cast<size_type>(-1)
- / sizeof(_CharT)) - 1) / 2) };
-
- // Data Members (private):
+ // Data Members:
typename _Util_Base::template _Alloc_hider<_CharT_alloc_type>
_M_dataplus;
size_type _M_string_length;
public:
size_type
_M_max_size() const
- { return size_type(_S_max_size); }
+ { return (_M_dataplus._CharT_alloc_type::max_size() - 1) / 2; }
_CharT*
_M_data() const
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 83. String::npos vs. string::max_size()
- if (__capacity > size_type(_S_max_size))
+ if (__capacity > _M_max_size())
std::__throw_length_error(__N("__sso_string_base::_M_create"));
// The below implements an exponential growth policy, necessary to
if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
{
__capacity = 2 * __old_capacity;
- // Never allocate a string bigger than _S_max_size.
- if (__capacity > size_type(_S_max_size))
- __capacity = size_type(_S_max_size);
+ // Never allocate a string bigger than max_size.
+ if (__capacity > _M_max_size())
+ __capacity = _M_max_size();
}
// NB: Need an array of char_type[__capacity], plus a terminating
typedef std::reverse_iterator<iterator> reverse_iterator;
// Data Member (public):
- // NB: This is an unsigned type, and thus represents the maximum
- // size that the allocator can hold.
/// Value returned by various member functions when they fail.
static const size_type npos = static_cast<size_type>(-1);
--- /dev/null
+// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 21.3.3 basic_string capacity [lib.string.capacity]
+
+#include <ext/vstring.h>
+#include <testsuite_hooks.h>
+
+// libstdc++/29134
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_cxx::__vstring vs;
+
+ VERIFY( vs.max_size() <= vs.get_allocator().max_size() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}