summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/vector.tcc
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2002-11-13 22:15:17 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2002-11-13 22:15:17 +0000
commit0a74e2ae4ae4d44fc7d972ba30190e54718e0b97 (patch)
tree34209be2f1268c7cac587baa4d7ec94537df451b /libstdc++-v3/include/bits/vector.tcc
parentb9824c82353bab7032ab61c2d5ce27b8aca8b25e (diff)
downloadgcc-0a74e2ae4ae4d44fc7d972ba30190e54718e0b97.tar.gz
2002-11-13 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/8230 * include/bits/vector.tcc (vector::reserve): Throw length_error if requested size is bigger than max_size(). * include/bits/stl_bvector.h (vector<bool>::reserve): Same. * testsuite/23_containers/vector_capacity.cc (test02): Add. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59090 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/vector.tcc')
-rw-r--r--libstdc++-v3/include/bits/vector.tcc22
1 files changed, 12 insertions, 10 deletions
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 9b21d0da9fc..4e742dd8672 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -68,16 +68,18 @@ namespace std
vector<_Tp,_Alloc>::
reserve(size_type __n)
{
- if (capacity() < __n)
- {
- const size_type __old_size = size();
- pointer __tmp = _M_allocate_and_copy(__n, _M_start, _M_finish);
- _Destroy(_M_start, _M_finish);
- _M_deallocate(_M_start, _M_end_of_storage - _M_start);
- _M_start = __tmp;
- _M_finish = __tmp + __old_size;
- _M_end_of_storage = _M_start + __n;
- }
+ if (__n > this->max_size())
+ __throw_length_error("vector::reserve");
+ if (this->capacity() < __n)
+ {
+ const size_type __old_size = size();
+ pointer __tmp = _M_allocate_and_copy(__n, _M_start, _M_finish);
+ _Destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __tmp;
+ _M_finish = __tmp + __old_size;
+ _M_end_of_storage = _M_start + __n;
+ }
}
template <typename _Tp, typename _Alloc>