re PR libstdc++/58338 (Add noexcept to functions with a narrow contract)

2013-09-17  Marc Glisse  <marc.glisse@inria.fr>

	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
This commit is contained in:
Marc Glisse 2013-09-17 14:23:54 +02:00 committed by Marc Glisse
parent 9a0ac98faf
commit 757b16440b
8 changed files with 73 additions and 45 deletions

View File

@ -1,3 +1,37 @@
2013-09-17 Marc Glisse <marc.glisse@inria.fr>
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 <timshen91@gmail.com> 2013-09-14 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h (regex_match<>, regex_search<>): * include/bits/regex.h (regex_match<>, regex_search<>):

View File

@ -87,18 +87,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _Tp_alloc_type(), _M_start(0), _M_finish(0), _M_end_of_storage(0) : _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) : _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0)
{ } { }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_Vector_impl(_Tp_alloc_type&& __a) _Vector_impl(_Tp_alloc_type&& __a) noexcept
: _Tp_alloc_type(std::move(__a)), : _Tp_alloc_type(std::move(__a)),
_M_start(0), _M_finish(0), _M_end_of_storage(0) _M_start(0), _M_finish(0), _M_end_of_storage(0)
{ } { }
#endif #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_start, __x._M_start);
std::swap(_M_finish, __x._M_finish); std::swap(_M_finish, __x._M_finish);
@ -124,7 +124,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Vector_base() _Vector_base()
: _M_impl() { } : _M_impl() { }
_Vector_base(const allocator_type& __a) _Vector_base(const allocator_type& __a) _GLIBCXX_NOEXCEPT
: _M_impl(__a) { } : _M_impl(__a) { }
_Vector_base(size_t __n) _Vector_base(size_t __n)
@ -136,10 +136,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ _M_create_storage(__n); } { _M_create_storage(__n); }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_Vector_base(_Tp_alloc_type&& __a) _Vector_base(_Tp_alloc_type&& __a) noexcept
: _M_impl(std::move(__a)) { } : _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())) : _M_impl(std::move(__x._M_get_Tp_allocator()))
{ this->_M_impl._M_swap_data(__x._M_impl); } { this->_M_impl._M_swap_data(__x._M_impl); }
@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
} }
#endif #endif
~_Vector_base() ~_Vector_base() _GLIBCXX_NOEXCEPT
{ _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
- this->_M_impl._M_start); } - this->_M_impl._M_start); }
@ -242,18 +242,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
public: public:
// [23.2.4.1] construct/copy/destroy // [23.2.4.1] construct/copy/destroy
// (assign() and get_allocator() are also listed in this section) // (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. * @brief Creates a %vector with no elements.
* @param __a An allocator object. * @param __a An allocator object.
*/ */
explicit explicit
vector(const allocator_type& __a) vector(const allocator_type& __a = allocator_type()) _GLIBCXX_NOEXCEPT
: _Base(__a) { } : _Base(__a) { }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
@ -767,7 +761,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* see at().) * see at().)
*/ */
reference reference
operator[](size_type __n) operator[](size_type __n) _GLIBCXX_NOEXCEPT
{ return *(this->_M_impl._M_start + __n); } { return *(this->_M_impl._M_start + __n); }
/** /**
@ -782,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* see at().) * see at().)
*/ */
const_reference const_reference
operator[](size_type __n) const operator[](size_type __n) const _GLIBCXX_NOEXCEPT
{ return *(this->_M_impl._M_start + __n); } { return *(this->_M_impl._M_start + __n); }
protected: protected:
@ -836,7 +830,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* element of the %vector. * element of the %vector.
*/ */
reference reference
front() front() _GLIBCXX_NOEXCEPT
{ return *begin(); } { return *begin(); }
/** /**
@ -844,7 +838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* element of the %vector. * element of the %vector.
*/ */
const_reference const_reference
front() const front() const _GLIBCXX_NOEXCEPT
{ return *begin(); } { return *begin(); }
/** /**
@ -852,7 +846,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* element of the %vector. * element of the %vector.
*/ */
reference reference
back() back() _GLIBCXX_NOEXCEPT
{ return *(end() - 1); } { return *(end() - 1); }
/** /**
@ -860,7 +854,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* last element of the %vector. * last element of the %vector.
*/ */
const_reference const_reference
back() const back() const _GLIBCXX_NOEXCEPT
{ return *(end() - 1); } { return *(end() - 1); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
@ -934,7 +928,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* called. * called.
*/ */
void void
pop_back() pop_back() _GLIBCXX_NOEXCEPT
{ {
--this->_M_impl._M_finish; --this->_M_impl._M_finish;
_Alloc_traits::destroy(this->_M_impl, 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, // Called by erase(q1,q2), clear(), resize(), _M_fill_assign,
// _M_assign_aux. // _M_assign_aux.
void 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()); std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator());
this->_M_impl._M_finish = __pos; this->_M_impl._M_finish = __pos;

View File

@ -76,7 +76,7 @@ namespace __debug
// 23.2.4.1 construct/copy/destroy: // 23.2.4.1 construct/copy/destroy:
explicit explicit
vector(const _Allocator& __a = _Allocator()) vector(const _Allocator& __a = _Allocator()) _GLIBCXX_NOEXCEPT
: _Base(__a), _M_guaranteed_capacity(0) { } : _Base(__a), _M_guaranteed_capacity(0) { }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
@ -341,14 +341,14 @@ namespace __debug
// element access: // element access:
reference reference
operator[](size_type __n) operator[](size_type __n) _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_subscript(__n); __glibcxx_check_subscript(__n);
return _M_base()[__n]; return _M_base()[__n];
} }
const_reference const_reference
operator[](size_type __n) const operator[](size_type __n) const _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_subscript(__n); __glibcxx_check_subscript(__n);
return _M_base()[__n]; return _M_base()[__n];
@ -357,28 +357,28 @@ namespace __debug
using _Base::at; using _Base::at;
reference reference
front() front() _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_nonempty(); __glibcxx_check_nonempty();
return _Base::front(); return _Base::front();
} }
const_reference const_reference
front() const front() const _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_nonempty(); __glibcxx_check_nonempty();
return _Base::front(); return _Base::front();
} }
reference reference
back() back() _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_nonempty(); __glibcxx_check_nonempty();
return _Base::back(); return _Base::back();
} }
const_reference const_reference
back() const back() const _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_nonempty(); __glibcxx_check_nonempty();
return _Base::back(); return _Base::back();
@ -419,7 +419,7 @@ namespace __debug
#endif #endif
void void
pop_back() pop_back() _GLIBCXX_NOEXCEPT
{ {
__glibcxx_check_nonempty(); __glibcxx_check_nonempty();
this->_M_invalidate_if(_Equal(--_Base::end())); this->_M_invalidate_if(_Equal(--_Base::end()));
@ -630,18 +630,18 @@ namespace __debug
size_type _M_guaranteed_capacity; size_type _M_guaranteed_capacity;
bool bool
_M_requires_reallocation(size_type __elements) _M_requires_reallocation(size_type __elements) _GLIBCXX_NOEXCEPT
{ return __elements > this->capacity(); } { return __elements > this->capacity(); }
void void
_M_update_guaranteed_capacity() _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
{ {
if (this->size() > _M_guaranteed_capacity) if (this->size() > _M_guaranteed_capacity)
_M_guaranteed_capacity = this->size(); _M_guaranteed_capacity = this->size();
} }
void 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; typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth;
this->_M_invalidate_if(_After_nth(__n, _Base::begin())); this->_M_invalidate_if(_After_nth(__n, _Base::begin()));

View File

@ -78,7 +78,7 @@ namespace __profile
// 23.2.4.1 construct/copy/destroy: // 23.2.4.1 construct/copy/destroy:
explicit explicit
vector(const _Allocator& __a = _Allocator()) vector(const _Allocator& __a = _Allocator()) _GLIBCXX_NOEXCEPT
: _Base(__a) : _Base(__a)
{ {
__profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct(this, this->capacity());
@ -156,7 +156,7 @@ namespace __profile
__profcxx_vector_construct2(this); __profcxx_vector_construct2(this);
} }
vector(vector&& __x, const _Allocator& __a) noexcept vector(vector&& __x, const _Allocator& __a)
: _Base(std::move(__x), __a) : _Base(std::move(__x), __a)
{ {
__profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct(this, this->capacity());
@ -292,13 +292,13 @@ namespace __profile
// element access: // element access:
reference reference
operator[](size_type __n) operator[](size_type __n) _GLIBCXX_NOEXCEPT
{ {
__profcxx_vector_invalid_operator(this); __profcxx_vector_invalid_operator(this);
return _M_base()[__n]; return _M_base()[__n];
} }
const_reference const_reference
operator[](size_type __n) const operator[](size_type __n) const _GLIBCXX_NOEXCEPT
{ {
__profcxx_vector_invalid_operator(this); __profcxx_vector_invalid_operator(this);
return _M_base()[__n]; return _M_base()[__n];
@ -307,25 +307,25 @@ namespace __profile
using _Base::at; using _Base::at;
reference reference
front() front() _GLIBCXX_NOEXCEPT
{ {
return _Base::front(); return _Base::front();
} }
const_reference const_reference
front() const front() const _GLIBCXX_NOEXCEPT
{ {
return _Base::front(); return _Base::front();
} }
reference reference
back() back() _GLIBCXX_NOEXCEPT
{ {
return _Base::back(); return _Base::back();
} }
const_reference const_reference
back() const back() const _GLIBCXX_NOEXCEPT
{ {
return _Base::back(); return _Base::back();
} }

View File

@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1308 } // { dg-error "no matching" "" { target *-*-* } 1302 }
#include <vector> #include <vector>

View File

@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1234 } // { dg-error "no matching" "" { target *-*-* } 1228 }
#include <vector> #include <vector>

View File

@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1234 } // { dg-error "no matching" "" { target *-*-* } 1228 }
#include <vector> #include <vector>
#include <utility> #include <utility>

View File

@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1349 } // { dg-error "no matching" "" { target *-*-* } 1343 }
#include <vector> #include <vector>