From dc2cf706b84723741ca863f04fcfde3834e60747 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 18 Jun 2010 18:07:45 +0000 Subject: [PATCH] re PR libstdc++/32618 (std::vector calls uneccessary constructors instead of inplace construction of first object) 2010-06-18 Paolo Carlini PR libstdc++/32618 * include/bits/stl_list.h (vector<>::_M_default_initialize, _M_default_append): Declare. (list<>::list(size_type), resize(size_type)): Add in C++0x mode, use the latter. * include/bits/list.tcc (list<>::resize, _M_default_append): Define. * include/bits/stl_vector.h (vector<>::_M_default_initialize, _M_default_append): Declare. (vector<>::vector(size_type), resize(size_type)): Add in C++0x mode, use the latter. * include/bits/vector.tcc (vector<>::_M_default_append): Define. * include/bits/stl_deque.h (deque<>::_M_default_initialize, _M_default_append): Declare. (deque<>::deque(size_type), resize(size_type)): Add in C++0x mode, use the latter. * include/bits/deque.tcc (deque<>::_M_default_append): Define. * include/debug/vector: Update. * include/debug/deque: Likewise. * include/debug/list: Likewise. * include/profile/vector: Likewise. * include/profile/deque: Likewise. * include/profile/list: Likewise. * include/bits/forward_list.h (_M_default_initialize, _M_default_insert_after): Declare. (forward_list<>::forward_list(size_type), resize(size_type)): Fix, use the latter. * include/bits/forward_list.tcc (forward_list<>::_M_default_append, _M_default_insert_after): Define. * testsuite/util/testsuite_api.h (NonCopyConstructible): Add. * testsuite/23_containers/forward_list/modifiers/6.cc: Move to... * testsuite/23_containers/forward_list/capacity/resize_size.cc: ... here. * testsuite/23_containers/forward_list/cons/10.cc: Move to... * testsuite/23_containers/forward_list/cons/cons_size.cc: ... here. * testsuite/23_containers/vector/resize/1.cc: Move to... * testsuite/23_containers/vector/capacity/resize/1.cc: ... here. * testsuite/23_containers/vector/resize/moveable.cc: Move to... * testsuite/23_containers/vector/resize/capacity/moveable.cc: ... here. * testsuite/23_containers/vector/cons/cons_size.cc: New. * testsuite/23_containers/vector/capacity/resize/resize_size.cc: Likewise. * testsuite/23_containers/deque/cons/cons_size.cc: Likewise. * testsuite/23_containers/deque/capacity/resize_size.cc: Likewise. * testsuite/23_containers/list/cons/cons_size.cc: Likewise. * testsuite/23_containers/list/capacity/resize_size.cc: Likewise. * testsuite/23_containers/vector/capacity/resize/moveable.cc: Adjust. * testsuite/23_containers/deque/capacity/moveable.cc: Likewise. * testsuite/23_containers/forward_list/requirements/dr438/ assign_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/forward_list/requirements/dr438/ insert_neg.cc: Likewise. * testsuite/23_containers/forward_list/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/forward_list/requirements/dr438/ constructor_2_neg.cc: Likewise. * testsuite/23_containers/vector/requirements/dr438/ assign_neg.cc: Likewise. * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Likewise. * testsuite/23_containers/vector/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/vector/requirements/dr438/ constructor_2_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/ assign_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/ constructor_2_neg.cc: Likewise. * testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Likewise. * testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Likewise. * testsuite/23_containers/list/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/list/requirements/dr438/ constructor_2_neg.cc: Likewise. From-SVN: r161009 --- libstdc++-v3/ChangeLog | 82 ++++++++++++++ libstdc++-v3/include/bits/deque.tcc | 56 +++++++++- libstdc++-v3/include/bits/forward_list.h | 12 +- libstdc++-v3/include/bits/forward_list.tcc | 31 ++++-- libstdc++-v3/include/bits/list.tcc | 51 +++++++++ libstdc++-v3/include/bits/stl_deque.h | 104 ++++++++++++++++-- libstdc++-v3/include/bits/stl_list.h | 69 +++++++++++- libstdc++-v3/include/bits/stl_vector.h | 97 +++++++++++++++- libstdc++-v3/include/bits/vector.tcc | 53 +++++++++ libstdc++-v3/include/debug/deque | 52 ++++++++- libstdc++-v3/include/debug/list | 76 ++++++++++++- libstdc++-v3/include/debug/vector | 44 +++++++- libstdc++-v3/include/profile/deque | 32 +++++- libstdc++-v3/include/profile/list | 36 +++++- libstdc++-v3/include/profile/vector | 44 +++++++- .../23_containers/deque/capacity/moveable.cc | 33 ++---- .../deque/capacity/resize_size.cc | 43 ++++++++ .../23_containers/deque/cons/cons_size.cc | 40 +++++++ .../deque/requirements/dr438/assign_neg.cc | 2 +- .../requirements/dr438/constructor_1_neg.cc | 2 +- .../requirements/dr438/constructor_2_neg.cc | 4 +- .../deque/requirements/dr438/insert_neg.cc | 2 +- .../{cons/10.cc => capacity/resize_size.cc} | 19 +--- .../{modifiers/6.cc => cons/cons_size.cc} | 19 +--- .../requirements/dr438/assign_neg.cc | 2 +- .../requirements/dr438/constructor_1_neg.cc | 2 +- .../requirements/dr438/constructor_2_neg.cc | 2 +- .../requirements/dr438/insert_neg.cc | 2 +- .../list/capacity/resize_size.cc | 43 ++++++++ .../23_containers/list/cons/cons_size.cc | 40 +++++++ .../list/requirements/dr438/assign_neg.cc | 2 +- .../requirements/dr438/constructor_1_neg.cc | 2 +- .../requirements/dr438/constructor_2_neg.cc | 2 +- .../list/requirements/dr438/insert_neg.cc | 2 +- .../vector/{ => capacity}/resize/1.cc | 0 .../vector/{ => capacity}/resize/moveable.cc | 37 ++----- .../vector/capacity/resize/resize_size.cc | 43 ++++++++ .../23_containers/vector/cons/cons_size.cc | 40 +++++++ .../vector/requirements/dr438/assign_neg.cc | 2 +- .../requirements/dr438/constructor_1_neg.cc | 2 +- .../requirements/dr438/constructor_2_neg.cc | 2 +- .../vector/requirements/dr438/insert_neg.cc | 2 +- libstdc++-v3/testsuite/util/testsuite_api.h | 24 +++- 43 files changed, 1112 insertions(+), 142 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc create mode 100644 libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc rename libstdc++-v3/testsuite/23_containers/forward_list/{cons/10.cc => capacity/resize_size.cc} (79%) rename libstdc++-v3/testsuite/23_containers/forward_list/{modifiers/6.cc => cons/cons_size.cc} (75%) create mode 100644 libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc rename libstdc++-v3/testsuite/23_containers/vector/{ => capacity}/resize/1.cc (100%) rename libstdc++-v3/testsuite/23_containers/vector/{ => capacity}/resize/moveable.cc (50%) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e0c2f30444c..58410cca40c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,85 @@ +2010-06-18 Paolo Carlini + + PR libstdc++/32618 + * include/bits/stl_list.h (vector<>::_M_default_initialize, + _M_default_append): Declare. + (list<>::list(size_type), resize(size_type)): Add in C++0x mode, + use the latter. + * include/bits/list.tcc (list<>::resize, _M_default_append): Define. + * include/bits/stl_vector.h (vector<>::_M_default_initialize, + _M_default_append): Declare. + (vector<>::vector(size_type), resize(size_type)): Add in C++0x mode, + use the latter. + * include/bits/vector.tcc (vector<>::_M_default_append): Define. + * include/bits/stl_deque.h (deque<>::_M_default_initialize, + _M_default_append): Declare. + (deque<>::deque(size_type), resize(size_type)): Add in C++0x mode, + use the latter. + * include/bits/deque.tcc (deque<>::_M_default_append): Define. + * include/debug/vector: Update. + * include/debug/deque: Likewise. + * include/debug/list: Likewise. + * include/profile/vector: Likewise. + * include/profile/deque: Likewise. + * include/profile/list: Likewise. + * include/bits/forward_list.h (_M_default_initialize, + _M_default_insert_after): Declare. + (forward_list<>::forward_list(size_type), resize(size_type)): Fix, + use the latter. + * include/bits/forward_list.tcc (forward_list<>::_M_default_append, + _M_default_insert_after): Define. + * testsuite/util/testsuite_api.h (NonCopyConstructible): Add. + * testsuite/23_containers/forward_list/modifiers/6.cc: Move to... + * testsuite/23_containers/forward_list/capacity/resize_size.cc: + ... here. + * testsuite/23_containers/forward_list/cons/10.cc: Move to... + * testsuite/23_containers/forward_list/cons/cons_size.cc: ... here. + * testsuite/23_containers/vector/resize/1.cc: Move to... + * testsuite/23_containers/vector/capacity/resize/1.cc: ... here. + * testsuite/23_containers/vector/resize/moveable.cc: Move to... + * testsuite/23_containers/vector/resize/capacity/moveable.cc: ... here. + * testsuite/23_containers/vector/cons/cons_size.cc: New. + * testsuite/23_containers/vector/capacity/resize/resize_size.cc: + Likewise. + * testsuite/23_containers/deque/cons/cons_size.cc: Likewise. + * testsuite/23_containers/deque/capacity/resize_size.cc: Likewise. + * testsuite/23_containers/list/cons/cons_size.cc: Likewise. + * testsuite/23_containers/list/capacity/resize_size.cc: Likewise. + * testsuite/23_containers/vector/capacity/resize/moveable.cc: Adjust. + * testsuite/23_containers/deque/capacity/moveable.cc: Likewise. + * testsuite/23_containers/forward_list/requirements/dr438/ + assign_neg.cc: Adjust dg-error line numbers. + * testsuite/23_containers/forward_list/requirements/dr438/ + insert_neg.cc: Likewise. + * testsuite/23_containers/forward_list/requirements/dr438/ + constructor_1_neg.cc: Likewise. + * testsuite/23_containers/forward_list/requirements/dr438/ + constructor_2_neg.cc: Likewise. + * testsuite/23_containers/vector/requirements/dr438/ + assign_neg.cc: Likewise. + * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: + Likewise. + * testsuite/23_containers/vector/requirements/dr438/ + constructor_1_neg.cc: Likewise. + * testsuite/23_containers/vector/requirements/dr438/ + constructor_2_neg.cc: Likewise. + * testsuite/23_containers/deque/requirements/dr438/ + assign_neg.cc: Likewise. + * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: + Likewise. + * testsuite/23_containers/deque/requirements/dr438/ + constructor_1_neg.cc: Likewise. + * testsuite/23_containers/deque/requirements/dr438/ + constructor_2_neg.cc: Likewise. + * testsuite/23_containers/list/requirements/dr438/assign_neg.cc: + Likewise. + * testsuite/23_containers/list/requirements/dr438/insert_neg.cc: + Likewise. + * testsuite/23_containers/list/requirements/dr438/ + constructor_1_neg.cc: Likewise. + * testsuite/23_containers/list/requirements/dr438/ + constructor_2_neg.cc: Likewise. + 2010-06-17 Paolo Carlini * include/bits/stl_uninitialized.h (__uninitialized_default, diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index cde067cf382..d8c27870647 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1,6 +1,7 @@ // Deque implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +// 2009, 2010 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -59,6 +60,33 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + void + deque<_Tp, _Alloc>:: + _M_default_initialize() + { + _Map_pointer __cur; + __try + { + for (__cur = this->_M_impl._M_start._M_node; + __cur < this->_M_impl._M_finish._M_node; + ++__cur) + std::__uninitialized_default_a(*__cur, *__cur + _S_buffer_size(), + _M_get_Tp_allocator()); + std::__uninitialized_default_a(this->_M_impl._M_finish._M_first, + this->_M_impl._M_finish._M_cur, + _M_get_Tp_allocator()); + } + __catch(...) + { + std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur), + _M_get_Tp_allocator()); + __throw_exception_again; + } + } +#endif + template deque<_Tp, _Alloc>& deque<_Tp, _Alloc>:: @@ -271,6 +299,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_insert_aux(__pos, __n, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + void + deque<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + if (__n) + { + iterator __new_finish = _M_reserve_elements_at_back(__n); + __try + { + std::__uninitialized_default_a(this->_M_impl._M_finish, + __new_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = __new_finish; + } + __catch(...) + { + _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1, + __new_finish._M_node + 1); + __throw_exception_again; + } + } + } +#endif + template void deque<_Tp, _Alloc>:: diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index c0c135cd1b3..3708a62c37d 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -463,7 +463,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) * constructed elements. */ explicit - forward_list(size_type __n); + forward_list(size_type __n) + : _Base() + { _M_default_initialize(__n); } /** * @brief Creates a %forward_list with copies of an exemplar element. @@ -1209,6 +1211,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Called by splice_after and insert_after. iterator _M_splice_after(const_iterator __pos, forward_list&& __list); + + // Called by forward_list(n). + void + _M_default_initialize(size_type __n); + + // Called by resize(sz). + void + _M_default_insert_after(const_iterator __pos, size_type __n); }; /** diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc index 7468a90d1af..a3719a8698d 100644 --- a/libstdc++-v3/include/bits/forward_list.tcc +++ b/libstdc++-v3/include/bits/forward_list.tcc @@ -114,7 +114,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_fill_initialize(size_type __n, const value_type& __value) { _Node_base* __to = &this->_M_impl._M_head; - for (; __n > 0; --__n) + for (; __n; --__n) { __to->_M_next = this->_M_create_node(__value); __to = __to->_M_next; @@ -122,12 +122,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } template + void forward_list<_Tp, _Alloc>:: - forward_list(size_type __n) - : _Base() + _M_default_initialize(size_type __n) { _Node_base* __to = &this->_M_impl._M_head; - for (; __n > 0; --__n) + for (; __n; --__n) { __to->_M_next = this->_M_create_node(); __to = __to->_M_next; @@ -161,6 +161,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } + template + void + forward_list<_Tp, _Alloc>:: + _M_default_insert_after(const_iterator __pos, size_type __n) + { + const_iterator __saved_pos = __pos; + __try + { + for (; __n; --__n) + __pos = emplace_after(__pos); + } + __catch(...) + { + erase_after(__saved_pos, ++__pos); + __throw_exception_again; + } + } + template void forward_list<_Tp, _Alloc>:: @@ -177,10 +195,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (__len == __sz) erase_after(__k, end()); else - { - forward_list __tmp(__sz - __len); - splice_after(__k, std::move(__tmp)); - } + _M_default_insert_after(__k, __sz - __len); } template diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index f1c4a10dd66..3446c42a85b 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -112,6 +112,56 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) return __ret; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + void + list<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + size_type __i = 0; + __try + { + for (; __i < __n; ++__i) + emplace_back(); + } + __catch(...) + { + for (; __i; --__i) + pop_back(); + __throw_exception_again; + } + } + + template + void + list<_Tp, _Alloc>:: + resize(size_type __new_size) + { + iterator __i = begin(); + size_type __len = 0; + for (; __i != end() && __len < __new_size; ++__i, ++__len) + ; + if (__len == __new_size) + erase(__i, end()); + else // __i == end() + _M_default_append(__new_size - __len); + } + + template + void + list<_Tp, _Alloc>:: + resize(size_type __new_size, const value_type& __x) + { + iterator __i = begin(); + size_type __len = 0; + for (; __i != end() && __len < __new_size; ++__i, ++__len) + ; + if (__len == __new_size) + erase(__i, end()); + else // __i == end() + insert(end(), __new_size - __len, __x); + } +#else template void list<_Tp, _Alloc>:: @@ -126,6 +176,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) else // __i == end() insert(end(), __new_size - __len, __x); } +#endif template list<_Tp, _Alloc>& diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 19022b0cf34..d3cd73997e9 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -449,6 +449,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) : _M_impl() { _M_initialize_map(0); } + _Deque_base(size_t __num_elements) + : _M_impl() + { _M_initialize_map(__num_elements); } + _Deque_base(const allocator_type& __a, size_t __num_elements) : _M_impl(__a) { _M_initialize_map(__num_elements); } @@ -773,6 +777,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) deque(const allocator_type& __a) : _Base(__a, 0) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %deque with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %deque with @a n default + * constructed elements. + */ + explicit + deque(size_type __n) + : _Base(__n) + { _M_default_initialize(); } + + /** + * @brief Creates a %deque with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %deque with @a n copies of @a value. + */ + deque(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__a, __n) + { _M_fill_initialize(__value); } +#else /** * @brief Creates a %deque with copies of an exemplar element. * @param n The number of elements to initially create. @@ -786,6 +816,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__a, __n) { _M_fill_initialize(__value); } +#endif /** * @brief %Deque copy constructor. @@ -824,11 +855,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ deque(initializer_list __l, const allocator_type& __a = allocator_type()) - : _Base(__a) - { - _M_range_initialize(__l.begin(), __l.end(), - random_access_iterator_tag()); - } + : _Base(__a) + { + _M_range_initialize(__l.begin(), __l.end(), + random_access_iterator_tag()); + } #endif /** @@ -1086,6 +1117,49 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Tp_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %deque to the specified number of elements. + * @param new_size Number of elements the %deque should contain. + * + * This function will %resize the %deque to the specified + * number of elements. If the number is smaller than the + * %deque's current size the %deque is truncated, otherwise + * default constructed elements are appended. + */ + void + resize(size_type __new_size) + { + const size_type __len = size(); + if (__new_size > __len) + _M_default_append(__new_size - __len); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); + } + + /** + * @brief Resizes the %deque to the specified number of elements. + * @param new_size Number of elements the %deque should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %deque to the specified + * number of elements. If the number is smaller than the + * %deque's current size the %deque is truncated, otherwise the + * %deque is extended and new elements are populated with given + * data. + */ + void + resize(size_type __new_size, const value_type& __x) + { + const size_type __len = size(); + if (__new_size > __len) + insert(this->_M_impl._M_finish, __new_size - __len, __x); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); + } +#else /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. @@ -1101,11 +1175,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) resize(size_type __new_size, value_type __x = value_type()) { const size_type __len = size(); - if (__new_size < __len) - _M_erase_at_end(this->_M_impl._M_start + difference_type(__new_size)); - else + if (__new_size > __len) insert(this->_M_impl._M_finish, __new_size - __len, __x); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** A non-binding request to reduce memory use. */ @@ -1564,6 +1640,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_initialize(const value_type& __value); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // called by deque(n). + void + _M_default_initialize(); +#endif + // Internal assign functions follow. The *_aux functions do the actual // assignment work for the range versions. @@ -1752,6 +1834,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->_M_impl._M_finish = __pos; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by resize(sz). + void + _M_default_append(size_type __n); +#endif + //@{ /// Memory-handling helpers for the previous internal insert functions. iterator diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 56357ed07da..d6f9255752f 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -508,6 +508,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) list(const allocator_type& __a) : _Base(__a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %list with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %list with @a n default + * constructed elements. + */ + explicit + list(size_type __n) + : _Base() + { _M_default_initialize(__n); } + + /** + * @brief Creates a %list with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator object. + * + * This constructor fills the %list with @a n copies of @a value. + */ + list(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { _M_fill_initialize(__n, __value); } +#else /** * @brief Creates a %list with copies of an exemplar element. * @param n The number of elements to initially create. @@ -521,6 +547,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %List copy constructor. @@ -811,6 +838,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Node_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %list to the specified number of elements. + * @param new_size Number of elements the %list should contain. + * + * This function will %resize the %list to the specified number + * of elements. If the number is smaller than the %list's + * current size the %list is truncated, otherwise default + * constructed elements are appended. + */ + void + resize(size_type __new_size); + + /** + * @brief Resizes the %list to the specified number of elements. + * @param new_size Number of elements the %list should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %list to the specified number + * of elements. If the number is smaller than the %list's + * current size the %list is truncated, otherwise the %list is + * extended and new elements are populated with given data. + */ + void + resize(size_type __new_size, const value_type& __x); +#else /** * @brief Resizes the %list to the specified number of elements. * @param new_size Number of elements the %list should contain. @@ -823,6 +876,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ void resize(size_type __new_size, value_type __x = value_type()); +#endif // element access /** @@ -1394,10 +1448,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_initialize(size_type __n, const value_type& __x) { - for (; __n > 0; --__n) + for (; __n; --__n) push_back(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by list(n). + void + _M_default_initialize(size_type __n) + { + for (; __n; --__n) + emplace_back(); + } + + // Called by resize(sz). + void + _M_default_append(size_type __n); +#endif // Internal assign functions follow. diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index f025b4eeb45..d51578c9e05 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -107,6 +107,14 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _Vector_base(const allocator_type& __a) : _M_impl(__a) { } + _Vector_base(size_t __n) + : _M_impl() + { + this->_M_impl._M_start = this->_M_allocate(__n); + this->_M_impl._M_finish = this->_M_impl._M_start; + this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; + } + _Vector_base(size_t __n, const allocator_type& __a) : _M_impl(__a) { @@ -215,6 +223,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) vector(const allocator_type& __a) : _Base(__a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %vector with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %vector with @a n default + * constructed elements. + */ + explicit + vector(size_type __n) + : _Base(__n) + { _M_default_initialize(__n); } + + /** + * @brief Creates a %vector with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %vector with @a n copies of @a value. + */ + vector(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__n, __a) + { _M_fill_initialize(__n, __value); } +#else /** * @brief Creates a %vector with copies of an exemplar element. * @param n The number of elements to initially create. @@ -228,6 +262,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__n, __a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %Vector copy constructor. @@ -538,6 +573,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Tp_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %vector to the specified number of elements. + * @param new_size Number of elements the %vector should contain. + * + * This function will %resize the %vector to the specified + * number of elements. If the number is smaller than the + * %vector's current size the %vector is truncated, otherwise + * default constructed elements are appended. + */ + void + resize(size_type __new_size) + { + if (__new_size > size()) + _M_default_append(__new_size - size()); + else if (__new_size < size()) + _M_erase_at_end(this->_M_impl._M_start + __new_size); + } + /** * @brief Resizes the %vector to the specified number of elements. * @param new_size Number of elements the %vector should contain. @@ -550,13 +604,34 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * given data. */ void - resize(size_type __new_size, value_type __x = value_type()) + resize(size_type __new_size, const value_type& __x) { - if (__new_size < size()) + if (__new_size > size()) + insert(end(), __new_size - size(), __x); + else if (__new_size < size()) _M_erase_at_end(this->_M_impl._M_start + __new_size); - else + } +#else + /** + * @brief Resizes the %vector to the specified number of elements. + * @param new_size Number of elements the %vector should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %vector to the specified + * number of elements. If the number is smaller than the + * %vector's current size the %vector is truncated, otherwise + * the %vector is extended and new elements are populated with + * given data. + */ + void + resize(size_type __new_size, value_type __x = value_type()) + { + if (__new_size > size()) insert(end(), __new_size - size(), __x); + else if (__new_size < size()) + _M_erase_at_end(this->_M_impl._M_start + __new_size); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** A non-binding request to reduce capacity() to size(). */ @@ -1049,6 +1124,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by the vector(n) constructor. + void + _M_default_initialize(size_type __n) + { + std::__uninitialized_default_n_a(this->_M_impl._M_start, __n, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; + } +#endif // Internal assign functions follow. The *_aux functions do the actual // assignment work for the range versions. @@ -1131,6 +1216,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by resize(n). + void + _M_default_append(size_type __n); +#endif + // Called by insert(p,x) #ifndef __GXX_EXPERIMENTAL_CXX0X__ void diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index e1097931048..846a0645d57 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -458,6 +458,59 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) } } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + void + vector<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + if (__n != 0) + { + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + std::__uninitialized_default_n_a(this->_M_impl._M_finish, + __n, _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n; + } + else + { + const size_type __len = + _M_check_len(__n, "vector::_M_default_append"); + const size_type __old_size = this->size(); + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); + __try + { + __new_finish = + std::__uninitialized_move_a(this->_M_impl._M_start, + this->_M_impl._M_finish, + __new_start, + _M_get_Tp_allocator()); + std::__uninitialized_default_n_a(__new_finish, __n, + _M_get_Tp_allocator()); + __new_finish += __n; + } + __catch(...) + { + std::_Destroy(__new_start, __new_finish, + _M_get_Tp_allocator()); + _M_deallocate(__new_start, __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; + } + } + } +#endif + template template void diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 0c98006badb..31f708a9c9d 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -67,12 +67,24 @@ namespace __debug typedef std::reverse_iterator const_reverse_iterator; // 23.2.1.1 construct/copy/destroy: - explicit deque(const _Allocator& __a = _Allocator()) + explicit + deque(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit deque(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + deque(size_type __n) + : _Base(__n) { } + + deque(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#else + explicit + deque(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#endif template deque(_InputIterator __first, _InputIterator __last, @@ -208,6 +220,39 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + typedef typename _Base::const_iterator _Base_const_iterator; + typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; + + bool __invalidate_all = __sz > this->size(); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + + _Base::resize(__sz); + + if (__invalidate_all) + this->_M_invalidate_all(); + } + + void + resize(size_type __sz, const _Tp& __c) + { + typedef typename _Base::const_iterator _Base_const_iterator; + typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; + + bool __invalidate_all = __sz > this->size(); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + + _Base::resize(__sz, __c); + + if (__invalidate_all) + this->_M_invalidate_all(); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -223,6 +268,7 @@ namespace __debug if (__invalidate_all) this->_M_invalidate_all(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 39a64818830..c65ed5829f2 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -67,12 +67,24 @@ namespace __debug typedef std::reverse_iterator const_reverse_iterator; // 23.2.2.1 construct/copy/destroy: - explicit list(const _Allocator& __a = _Allocator()) + explicit + list(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit list(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + list(size_type __n) + : _Base(__n) { } + + list(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#else + explicit + list(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#endif template list(_InputIterator __first, _InputIterator __last, @@ -208,6 +220,63 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + this->_M_detach_singular(); + + // if __sz < size(), invalidate all iterators in [begin+__sz, end()) + iterator __victim = begin(); + iterator __end = end(); + for (size_type __i = __sz; __victim != __end && __i > 0; --__i) + ++__victim; + + while (__victim != __end) + { + iterator __real_victim = __victim++; + __real_victim._M_invalidate(); + } + + __try + { + _Base::resize(__sz); + } + __catch(...) + { + this->_M_revalidate_singular(); + __throw_exception_again; + } + } + + void + resize(size_type __sz, const _Tp& __c) + { + this->_M_detach_singular(); + + // if __sz < size(), invalidate all iterators in [begin+__sz, end()) + iterator __victim = begin(); + iterator __end = end(); + for (size_type __i = __sz; __victim != __end && __i > 0; --__i) + ++__victim; + + while (__victim != __end) + { + iterator __real_victim = __victim++; + __real_victim._M_invalidate(); + } + + __try + { + _Base::resize(__sz, __c); + } + __catch(...) + { + this->_M_revalidate_singular(); + __throw_exception_again; + } + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -235,6 +304,7 @@ namespace __debug __throw_exception_again; } } +#endif // element access: reference diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index ea55b080442..c81f956212e 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -72,12 +72,24 @@ namespace __debug typedef std::reverse_iterator const_reverse_iterator; // 23.2.4.1 construct/copy/destroy: - explicit vector(const _Allocator& __a = _Allocator()) + explicit + vector(const _Allocator& __a = _Allocator()) : _Base(__a), _M_guaranteed_capacity(0) { } - explicit vector(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + vector(size_type __n) + : _Base(__n), _M_guaranteed_capacity(__n) { } + + vector(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a), _M_guaranteed_capacity(__n) { } +#else + explicit + vector(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a), _M_guaranteed_capacity(__n) { } +#endif template vector(_InputIterator __first, _InputIterator __last, @@ -226,6 +238,31 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + bool __realloc = _M_requires_reallocation(__sz); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + _Base::resize(__sz); + if (__realloc) + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + } + + void + resize(size_type __sz, const _Tp& __c) + { + bool __realloc = _M_requires_reallocation(__sz); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + _Base::resize(__sz, __c); + if (__realloc) + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -237,6 +274,7 @@ namespace __debug this->_M_invalidate_all(); _M_update_guaranteed_capacity(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/profile/deque b/libstdc++-v3/include/profile/deque index 55e8d49d686..9f8ce70c9db 100644 --- a/libstdc++-v3/include/profile/deque +++ b/libstdc++-v3/include/profile/deque @@ -60,12 +60,24 @@ namespace __profile typedef typename _Base::const_pointer const_pointer; // 23.2.1.1 construct/copy/destroy: - explicit deque(const _Allocator& __a = _Allocator()) + explicit + deque(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit deque(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + deque(size_type __n) + : _Base(__n) { } + + deque(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#else + explicit + deque(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#endif template deque(_InputIterator __first, _InputIterator __last, @@ -195,11 +207,25 @@ namespace __profile using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + _Base::resize(__sz); + } + + void + resize(size_type __sz, const _Tp& __c) + { + _Base::resize(__sz, __c); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { _Base::resize(__sz, __c); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/profile/list b/libstdc++-v3/include/profile/list index 01edd2919f6..e5468c44071 100644 --- a/libstdc++-v3/include/profile/list +++ b/libstdc++-v3/include/profile/list @@ -64,20 +64,40 @@ template > typedef std::reverse_iterator const_reverse_iterator; // 23.2.2.1 construct/copy/destroy: - explicit list(const _Allocator& __a = _Allocator()) + explicit + list(const _Allocator& __a = _Allocator()) : _Base(__a) { __profcxx_list_construct(this); // list2slist __profcxx_list_construct2(this); // list2vector } - explicit list(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + list(size_type __n) + : _Base(__n) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + list(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } +#else + explicit + list(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { __profcxx_list_construct(this); __profcxx_list_construct2(this); } +#endif template list(_InputIterator __first, _InputIterator __last, @@ -229,9 +249,19 @@ template > using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { _Base::resize(__sz); } + + void + resize(size_type __sz, const _Tp& __c) + { _Base::resize(__sz, __c); } +#else void resize(size_type __sz, _Tp __c = _Tp()) { _Base::resize(__sz, __c); } +#endif // element access: reference diff --git a/libstdc++-v3/include/profile/vector b/libstdc++-v3/include/profile/vector index ad74137583c..e6c32a38aec 100644 --- a/libstdc++-v3/include/profile/vector +++ b/libstdc++-v3/include/profile/vector @@ -76,20 +76,40 @@ namespace __profile _M_base() const { return *this; } // 23.2.4.1 construct/copy/destroy: - explicit vector(const _Allocator& __a = _Allocator()) + explicit + vector(const _Allocator& __a = _Allocator()) : _Base(__a) { __profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct2(this); } - explicit vector(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + vector(size_type __n) + : _Base(__n) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + vector(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { __profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct2(this); } +#else + explicit + vector(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } +#endif template vector(_InputIterator __first, _InputIterator __last, @@ -218,6 +238,23 @@ namespace __profile using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + __profcxx_vector_invalid_operator(this); + _M_profile_resize(this, this->capacity(), __sz); + _Base::resize(__sz); + } + + void + resize(size_type __sz, const _Tp& __c) + { + __profcxx_vector_invalid_operator(this); + _M_profile_resize(this, this->capacity(), __sz); + _Base::resize(__sz, __c); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -225,6 +262,7 @@ namespace __profile _M_profile_resize(this, this->capacity(), __sz); _Base::resize(__sz, __c); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc index 089b10b83a6..475880888cc 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006, 2007, 2009, 2010 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 @@ -17,16 +17,12 @@ // with this library; see the file COPYING3. If not see // . - #include #include #include using namespace __gnu_test; -// According to n1771, there should be two resizes, with and without -// parameter. We only have one at present, whose second parameter defaults -// to a default-constructed object. void test01() { @@ -38,30 +34,17 @@ test01() a.resize(98); a.resize(99); a.resize(100); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 100 ); -#else - VERIFY( copycounter::copycount == 100 + 4 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(99); a.resize(0); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 100 ); -#else - VERIFY( copycounter::copycount == 100 + 6 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(100); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 200 ); -#else - VERIFY( copycounter::copycount == 200 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.clear(); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 200 ); -#else - VERIFY( copycounter::copycount == 200 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); } diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc new file mode 100644 index 00000000000..229a0eb60bc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d; + VERIFY( std::distance(d.begin(), d.end()) == 0 ); + + d.resize(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc new file mode 100644 index 00000000000..0207fd7174c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc index 96be31cb62a..bd6ee636305 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1577 } +// { dg-error "no matching" "" { target *-*-* } 1659 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc index 59d4e2f4158..21c9d4e4f3c 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1516 } +// { dg-error "no matching" "" { target *-*-* } 1592 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc index 6208581b877..08f54d68018 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc @@ -1,6 +1,6 @@ // 2007-04-27 Paolo Carlini -// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation // // 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 @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1516 } +// { dg-error "no matching" "" { target *-*-* } 1592 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc index 7fb2479d02c..a5bd6065c1c 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1661 } +// { dg-error "no matching" "" { target *-*-* } 1743 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc similarity index 79% rename from libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc rename to libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc index 4e599dab6bc..e22af3cbc19 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc @@ -21,24 +21,17 @@ #include #include - -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; +#include void test01() { bool test __attribute__((unused)) = true; - std::forward_list fl(5); - VERIFY( std::distance(fl.begin(), fl.end()) == 5 ); + std::forward_list<__gnu_test::NonCopyConstructible> fl; + VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); + + fl.resize(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); for(auto it = fl.begin(); it != fl.end(); ++it) VERIFY( *it == -1 ); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc similarity index 75% rename from libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc rename to libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc index 985f592e602..3d07f672089 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc @@ -21,27 +21,14 @@ #include #include - -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; +#include void test01() { bool test __attribute__((unused)) = true; - std::forward_list fl; - VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); - - fl.resize(10); - VERIFY( std::distance(fl.begin(), fl.end()) == 10 ); + std::forward_list<__gnu_test::NonCopyConstructible> fl(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); for(auto it = fl.begin(); it != fl.end(); ++it) VERIFY( *it == -1 ); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc index 1625e3bc76b..aa0f3e07def 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc index 5acfcd1f47f..3975b051611 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc index dcf69089b00..0b0471c8cc9 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc index 22574fd081a..849eb643e87 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc b/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc new file mode 100644 index 00000000000..06424c0a8c1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l; + VERIFY( std::distance(l.begin(), l.end()) == 0 ); + + l.resize(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc new file mode 100644 index 00000000000..f59f520f928 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc index eb35a24c89d..2446157597f 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1411 } +// { dg-error "no matching" "" { target *-*-* } 1478 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc index 937404b26a8..cbac8e80cbf 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc index 74fc1b7a163..232bd042ddb 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc index 3aebda5ddb2..aefb1f583fd 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/vector/resize/1.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc similarity index 100% rename from libstdc++-v3/testsuite/23_containers/vector/resize/1.cc rename to libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/vector/resize/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc similarity index 50% rename from libstdc++-v3/testsuite/23_containers/vector/resize/moveable.cc rename to libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc index 47fdf8fcafa..5ba026dbeb5 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/resize/moveable.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc @@ -1,6 +1,7 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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 @@ -17,19 +18,12 @@ // with this library; see the file COPYING3. If not see // . - #include #include #include using namespace __gnu_test; -// According to n1771, there should be two resizes, with and without -// parameter. We only have one at present, whose second parameter defaults -// to a default-constructed object. -// Also, the values are one higher than might be expected because internally -// resize calls fill, which copies its input value in case it is already in -// the vector when the vector isn't moved. void test01() { @@ -41,30 +35,17 @@ test01() a.resize(98); a.resize(99); a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 4 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(99); a.resize(0); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 6 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.clear(); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc new file mode 100644 index 00000000000..d181168acf7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v; + VERIFY( std::distance(v.begin(), v.end()) == 0 ); + + v.resize(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc new file mode 100644 index 00000000000..a33ba1ad69e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc index b96b5359963..6925c1776a4 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1063 } +// { dg-error "no matching" "" { target *-*-* } 1148 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc index 950643857c5..662bf169b23 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1003 } +// { dg-error "no matching" "" { target *-*-* } 1078 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc index f17b541a4e0..fe2a2b25475 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1003 } +// { dg-error "no matching" "" { target *-*-* } 1078 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc index 19d3fd08c4b..9869af131df 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1104 } +// { dg-error "no matching" "" { target *-*-* } 1189 } // { dg-excess-errors "" } #include diff --git a/libstdc++-v3/testsuite/util/testsuite_api.h b/libstdc++-v3/testsuite/util/testsuite_api.h index fcb762eff66..11007904093 100644 --- a/libstdc++-v3/testsuite/util/testsuite_api.h +++ b/libstdc++-v3/testsuite/util/testsuite_api.h @@ -19,7 +19,6 @@ // . // -#include #include #include @@ -107,7 +106,7 @@ namespace __gnu_test // For 23 unordered_* requirements. struct NonDefaultConstructible_hash { - size_t + std::size_t operator()(NonDefaultConstructible) const { return 1; } }; @@ -170,10 +169,29 @@ namespace __gnu_test struct OverloadedAddress_hash { - size_t + std::size_t operator()(const OverloadedAddress&) const { return 1; } }; + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + struct NonCopyConstructible + { + NonCopyConstructible() : num(-1) { } + + NonCopyConstructible(NonCopyConstructible&& other) + : num(other.num) + { other.num = 0; } + + NonCopyConstructible(const NonCopyConstructible&) = delete; + + operator int() { return num; } + + private: + int num; + }; +#endif + } #endif -- 2.30.2