From 757b16440b5d9edd0979cd8b31fd5a92bc537b7b Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 17 Sep 2013 14:23:54 +0200 Subject: [PATCH] re PR libstdc++/58338 (Add noexcept to functions with a narrow contract) 2013-09-17 Marc Glisse PR libstdc++/58338 * include/bits/stl_vector.h (vector::vector(), vector::vector(const allocator_type&)): Merge. (_Vector_impl::_Vector_impl(_Tp_alloc_type const&), _Vector_impl::_Vector_impl(_Tp_alloc_type&&), _Vector_impl::_M_swap_data, _Vector_base::_Vector_base(const allocator_type&), _Vector_base::_Vector_base(allocator_type&&), _Vector_base::_Vector_base(_Vector_base&&), _Vector_base::~_Vector_base, vector::vector(const allocator_type&), vector::operator[], vector::operator[] const, vector::front, vector::front const, vector::back, vector::back const, vector::pop_back, vector::_M_erase_at_end): Mark as noexcept. * include/debug/vector (vector::vector(const _Allocator&), vector::operator[], vector::operator[] const, vector::front, vector::front const, vector::back, vector::back const, vector::pop_back, _M_requires_reallocation, _M_update_guaranteed_capacity, _M_invalidate_after_nth): Mark as noexcept. * include/profile/vector (vector::vector(const _Allocator&), vector::operator[], vector::operator[] const, vector::front, vector::front const, vector::back, vector::back const): Mark as noexcept. (vector::vector(vector&&, const _Allocator&)): Remove wrong noexcept. * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Adjust line number. * 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/vector/requirements/dr438/insert_neg.cc: Likewise. From-SVN: r202650 --- libstdc++-v3/ChangeLog | 34 +++++++++++++++++ libstdc++-v3/include/bits/stl_vector.h | 38 ++++++++----------- libstdc++-v3/include/debug/vector | 22 +++++------ libstdc++-v3/include/profile/vector | 16 ++++---- .../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 +- 8 files changed, 73 insertions(+), 45 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 96891056ac7..31fa21f0580 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,37 @@ +2013-09-17 Marc Glisse + + PR libstdc++/58338 + * include/bits/stl_vector.h (vector::vector(), + vector::vector(const allocator_type&)): Merge. + (_Vector_impl::_Vector_impl(_Tp_alloc_type const&), + _Vector_impl::_Vector_impl(_Tp_alloc_type&&), + _Vector_impl::_M_swap_data, + _Vector_base::_Vector_base(const allocator_type&), + _Vector_base::_Vector_base(allocator_type&&), + _Vector_base::_Vector_base(_Vector_base&&), _Vector_base::~_Vector_base, + vector::vector(const allocator_type&), vector::operator[], + vector::operator[] const, vector::front, vector::front const, + vector::back, vector::back const, vector::pop_back, + vector::_M_erase_at_end): Mark as noexcept. + * include/debug/vector (vector::vector(const _Allocator&), + vector::operator[], vector::operator[] const, vector::front, + vector::front const, vector::back, vector::back const, vector::pop_back, + _M_requires_reallocation, _M_update_guaranteed_capacity, + _M_invalidate_after_nth): Mark as noexcept. + * include/profile/vector (vector::vector(const _Allocator&), + vector::operator[], vector::operator[] const, vector::front, + vector::front const, vector::back, vector::back const): Mark as + noexcept. + (vector::vector(vector&&, const _Allocator&)): Remove wrong noexcept. + * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: + Adjust line number. + * 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/vector/requirements/dr438/insert_neg.cc: + Likewise. + 2013-09-14 Tim Shen * include/bits/regex.h (regex_match<>, regex_search<>): diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 726693918a3..03850b5e28f 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -87,18 +87,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER : _Tp_alloc_type(), _M_start(0), _M_finish(0), _M_end_of_storage(0) { } - _Vector_impl(_Tp_alloc_type const& __a) + _Vector_impl(_Tp_alloc_type const& __a) _GLIBCXX_NOEXCEPT : _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) { } #if __cplusplus >= 201103L - _Vector_impl(_Tp_alloc_type&& __a) + _Vector_impl(_Tp_alloc_type&& __a) noexcept : _Tp_alloc_type(std::move(__a)), _M_start(0), _M_finish(0), _M_end_of_storage(0) { } #endif - void _M_swap_data(_Vector_impl& __x) + void _M_swap_data(_Vector_impl& __x) _GLIBCXX_NOEXCEPT { std::swap(_M_start, __x._M_start); std::swap(_M_finish, __x._M_finish); @@ -124,7 +124,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Vector_base() : _M_impl() { } - _Vector_base(const allocator_type& __a) + _Vector_base(const allocator_type& __a) _GLIBCXX_NOEXCEPT : _M_impl(__a) { } _Vector_base(size_t __n) @@ -136,10 +136,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _M_create_storage(__n); } #if __cplusplus >= 201103L - _Vector_base(_Tp_alloc_type&& __a) + _Vector_base(_Tp_alloc_type&& __a) noexcept : _M_impl(std::move(__a)) { } - _Vector_base(_Vector_base&& __x) + _Vector_base(_Vector_base&& __x) noexcept : _M_impl(std::move(__x._M_get_Tp_allocator())) { this->_M_impl._M_swap_data(__x._M_impl); } @@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif - ~_Vector_base() + ~_Vector_base() _GLIBCXX_NOEXCEPT { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage - this->_M_impl._M_start); } @@ -242,18 +242,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER public: // [23.2.4.1] construct/copy/destroy // (assign() and get_allocator() are also listed in this section) - /** - * @brief Default constructor creates no elements. - */ - vector() - : _Base() { } - /** * @brief Creates a %vector with no elements. * @param __a An allocator object. */ explicit - vector(const allocator_type& __a) + vector(const allocator_type& __a = allocator_type()) _GLIBCXX_NOEXCEPT : _Base(__a) { } #if __cplusplus >= 201103L @@ -767,7 +761,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * see at().) */ reference - operator[](size_type __n) + operator[](size_type __n) _GLIBCXX_NOEXCEPT { return *(this->_M_impl._M_start + __n); } /** @@ -782,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * see at().) */ const_reference - operator[](size_type __n) const + operator[](size_type __n) const _GLIBCXX_NOEXCEPT { return *(this->_M_impl._M_start + __n); } protected: @@ -836,7 +830,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element of the %vector. */ reference - front() + front() _GLIBCXX_NOEXCEPT { return *begin(); } /** @@ -844,7 +838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element of the %vector. */ const_reference - front() const + front() const _GLIBCXX_NOEXCEPT { return *begin(); } /** @@ -852,7 +846,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element of the %vector. */ reference - back() + back() _GLIBCXX_NOEXCEPT { return *(end() - 1); } /** @@ -860,7 +854,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * last element of the %vector. */ const_reference - back() const + back() const _GLIBCXX_NOEXCEPT { return *(end() - 1); } // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -934,7 +928,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * called. */ void - pop_back() + pop_back() _GLIBCXX_NOEXCEPT { --this->_M_impl._M_finish; _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish); @@ -1415,7 +1409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // Called by erase(q1,q2), clear(), resize(), _M_fill_assign, // _M_assign_aux. void - _M_erase_at_end(pointer __pos) + _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT { std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish = __pos; diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 7b28177c2a0..e5b80649b9a 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -76,7 +76,7 @@ namespace __debug // 23.2.4.1 construct/copy/destroy: explicit - vector(const _Allocator& __a = _Allocator()) + vector(const _Allocator& __a = _Allocator()) _GLIBCXX_NOEXCEPT : _Base(__a), _M_guaranteed_capacity(0) { } #if __cplusplus >= 201103L @@ -341,14 +341,14 @@ namespace __debug // element access: reference - operator[](size_type __n) + operator[](size_type __n) _GLIBCXX_NOEXCEPT { __glibcxx_check_subscript(__n); return _M_base()[__n]; } const_reference - operator[](size_type __n) const + operator[](size_type __n) const _GLIBCXX_NOEXCEPT { __glibcxx_check_subscript(__n); return _M_base()[__n]; @@ -357,28 +357,28 @@ namespace __debug using _Base::at; reference - front() + front() _GLIBCXX_NOEXCEPT { __glibcxx_check_nonempty(); return _Base::front(); } const_reference - front() const + front() const _GLIBCXX_NOEXCEPT { __glibcxx_check_nonempty(); return _Base::front(); } reference - back() + back() _GLIBCXX_NOEXCEPT { __glibcxx_check_nonempty(); return _Base::back(); } const_reference - back() const + back() const _GLIBCXX_NOEXCEPT { __glibcxx_check_nonempty(); return _Base::back(); @@ -419,7 +419,7 @@ namespace __debug #endif void - pop_back() + pop_back() _GLIBCXX_NOEXCEPT { __glibcxx_check_nonempty(); this->_M_invalidate_if(_Equal(--_Base::end())); @@ -630,18 +630,18 @@ namespace __debug size_type _M_guaranteed_capacity; bool - _M_requires_reallocation(size_type __elements) + _M_requires_reallocation(size_type __elements) _GLIBCXX_NOEXCEPT { return __elements > this->capacity(); } void - _M_update_guaranteed_capacity() + _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT { if (this->size() > _M_guaranteed_capacity) _M_guaranteed_capacity = this->size(); } void - _M_invalidate_after_nth(difference_type __n) + _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT { typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; this->_M_invalidate_if(_After_nth(__n, _Base::begin())); diff --git a/libstdc++-v3/include/profile/vector b/libstdc++-v3/include/profile/vector index 3ef04ff0a7c..8f79df7f07c 100644 --- a/libstdc++-v3/include/profile/vector +++ b/libstdc++-v3/include/profile/vector @@ -78,7 +78,7 @@ namespace __profile // 23.2.4.1 construct/copy/destroy: explicit - vector(const _Allocator& __a = _Allocator()) + vector(const _Allocator& __a = _Allocator()) _GLIBCXX_NOEXCEPT : _Base(__a) { __profcxx_vector_construct(this, this->capacity()); @@ -156,7 +156,7 @@ namespace __profile __profcxx_vector_construct2(this); } - vector(vector&& __x, const _Allocator& __a) noexcept + vector(vector&& __x, const _Allocator& __a) : _Base(std::move(__x), __a) { __profcxx_vector_construct(this, this->capacity()); @@ -292,13 +292,13 @@ namespace __profile // element access: reference - operator[](size_type __n) + operator[](size_type __n) _GLIBCXX_NOEXCEPT { __profcxx_vector_invalid_operator(this); return _M_base()[__n]; } const_reference - operator[](size_type __n) const + operator[](size_type __n) const _GLIBCXX_NOEXCEPT { __profcxx_vector_invalid_operator(this); return _M_base()[__n]; @@ -307,25 +307,25 @@ namespace __profile using _Base::at; reference - front() + front() _GLIBCXX_NOEXCEPT { return _Base::front(); } const_reference - front() const + front() const _GLIBCXX_NOEXCEPT { return _Base::front(); } reference - back() + back() _GLIBCXX_NOEXCEPT { return _Base::back(); } const_reference - back() const + back() const _GLIBCXX_NOEXCEPT { return _Base::back(); } 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 f7353ab325c..388e57182cc 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 *-*-* } 1308 } +// { dg-error "no matching" "" { target *-*-* } 1302 } #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 f404a7009da..68cfab064f8 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 *-*-* } 1234 } +// { dg-error "no matching" "" { target *-*-* } 1228 } #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 070295676a5..35c03286a26 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 *-*-* } 1234 } +// { dg-error "no matching" "" { target *-*-* } 1228 } #include #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 95af05795ce..6ab70388b83 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 *-*-* } 1349 } +// { dg-error "no matching" "" { target *-*-* } 1343 } #include