Commit 0e1a966a by Marc Glisse Committed by Marc Glisse

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

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

	PR libstdc++/58338
	* include/bits/stl_tree.h (_Rb_tree_node_base) [_S_minimum, _S_maximum]:
	Mark as noexcept.
	(_Rb_tree_iterator) [_Rb_tree_iterator, operator*, operator->,
	operator++, operator--, operator==, operator!=]: Likewise.
	(_Rb_tree_const_iterator) [_Rb_tree_const_iterator, _M_const_cast,
	operator*, operator->, operator++, operator--, operator==, operator!=]:
	Likewise.
	(operator==(const _Rb_tree_iterator&, const _Rb_tree_const_iterator&),
	operator!=(const _Rb_tree_iterator&, const _Rb_tree_const_iterator&)):
	Likewise.
	(_Rb_tree) [_M_put_node, _M_destroy_node, _M_root, _M_leftmost,
	_M_rightmost, _M_begin, _M_end, _S_left, _S_right, _S_minimum,
	_S_maximum]: Likewise.
	* include/debug/string (basic_string) [basic_string(const _Allocator&),
	shrink_to_fit, operator[], pop_back]: Likewise.
	* include/ext/vstring.h (__versa_string) [_M_limit, _M_disjunct,
	_M_ibegin, _M_iend, __versa_string(const _Alloc&),
	operator=(__versa_string&&), shrink_to_fit, operator[], front,
	back, assign(__versa_string&&), swap]: Likewise.
	(__versa_string) [__versa_string(), __versa_string(const _Alloc&)]:
	Merge.

From-SVN: r202737
parent 06c055fc
2013-09-19 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/58338
* include/bits/stl_tree.h (_Rb_tree_node_base) [_S_minimum, _S_maximum]:
Mark as noexcept.
(_Rb_tree_iterator) [_Rb_tree_iterator, operator*, operator->,
operator++, operator--, operator==, operator!=]: Likewise.
(_Rb_tree_const_iterator) [_Rb_tree_const_iterator, _M_const_cast,
operator*, operator->, operator++, operator--, operator==, operator!=]:
Likewise.
(operator==(const _Rb_tree_iterator&, const _Rb_tree_const_iterator&),
operator!=(const _Rb_tree_iterator&, const _Rb_tree_const_iterator&)):
Likewise.
(_Rb_tree) [_M_put_node, _M_destroy_node, _M_root, _M_leftmost,
_M_rightmost, _M_begin, _M_end, _S_left, _S_right, _S_minimum,
_S_maximum]: Likewise.
* include/debug/string (basic_string) [basic_string(const _Allocator&),
shrink_to_fit, operator[], pop_back]: Likewise.
* include/ext/vstring.h (__versa_string) [_M_limit, _M_disjunct,
_M_ibegin, _M_iend, __versa_string(const _Alloc&),
operator=(__versa_string&&), shrink_to_fit, operator[], front,
back, assign(__versa_string&&), swap]: Likewise.
(__versa_string) [__versa_string(), __versa_string(const _Alloc&)]:
Merge.
2013-09-18 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/58338
......
......@@ -99,28 +99,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Base_ptr _M_right;
static _Base_ptr
_S_minimum(_Base_ptr __x)
_S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{
while (__x->_M_left != 0) __x = __x->_M_left;
return __x;
}
static _Const_Base_ptr
_S_minimum(_Const_Base_ptr __x)
_S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{
while (__x->_M_left != 0) __x = __x->_M_left;
return __x;
}
static _Base_ptr
_S_maximum(_Base_ptr __x)
_S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{
while (__x->_M_right != 0) __x = __x->_M_right;
return __x;
}
static _Const_Base_ptr
_S_maximum(_Const_Base_ptr __x)
_S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{
while (__x->_M_right != 0) __x = __x->_M_right;
return __x;
......@@ -167,31 +167,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
typedef _Rb_tree_node<_Tp>* _Link_type;
_Rb_tree_iterator()
_Rb_tree_iterator() _GLIBCXX_NOEXCEPT
: _M_node() { }
explicit
_Rb_tree_iterator(_Link_type __x)
_Rb_tree_iterator(_Link_type __x) _GLIBCXX_NOEXCEPT
: _M_node(__x) { }
reference
operator*() const
operator*() const _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(_M_node)->_M_value_field; }
pointer
operator->() const
operator->() const _GLIBCXX_NOEXCEPT
{ return std::__addressof(static_cast<_Link_type>
(_M_node)->_M_value_field); }
_Self&
operator++()
operator++() _GLIBCXX_NOEXCEPT
{
_M_node = _Rb_tree_increment(_M_node);
return *this;
}
_Self
operator++(int)
operator++(int) _GLIBCXX_NOEXCEPT
{
_Self __tmp = *this;
_M_node = _Rb_tree_increment(_M_node);
......@@ -199,14 +199,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
_Self&
operator--()
operator--() _GLIBCXX_NOEXCEPT
{
_M_node = _Rb_tree_decrement(_M_node);
return *this;
}
_Self
operator--(int)
operator--(int) _GLIBCXX_NOEXCEPT
{
_Self __tmp = *this;
_M_node = _Rb_tree_decrement(_M_node);
......@@ -214,11 +214,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
bool
operator==(const _Self& __x) const
operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
{ return _M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
{ return _M_node != __x._M_node; }
_Base_ptr _M_node;
......@@ -240,39 +240,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
typedef const _Rb_tree_node<_Tp>* _Link_type;
_Rb_tree_const_iterator()
_Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
: _M_node() { }
explicit
_Rb_tree_const_iterator(_Link_type __x)
_Rb_tree_const_iterator(_Link_type __x) _GLIBCXX_NOEXCEPT
: _M_node(__x) { }
_Rb_tree_const_iterator(const iterator& __it)
_Rb_tree_const_iterator(const iterator& __it) _GLIBCXX_NOEXCEPT
: _M_node(__it._M_node) { }
iterator
_M_const_cast() const
_M_const_cast() const _GLIBCXX_NOEXCEPT
{ return iterator(static_cast<typename iterator::_Link_type>
(const_cast<typename iterator::_Base_ptr>(_M_node))); }
reference
operator*() const
operator*() const _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(_M_node)->_M_value_field; }
pointer
operator->() const
operator->() const _GLIBCXX_NOEXCEPT
{ return std::__addressof(static_cast<_Link_type>
(_M_node)->_M_value_field); }
_Self&
operator++()
operator++() _GLIBCXX_NOEXCEPT
{
_M_node = _Rb_tree_increment(_M_node);
return *this;
}
_Self
operator++(int)
operator++(int) _GLIBCXX_NOEXCEPT
{
_Self __tmp = *this;
_M_node = _Rb_tree_increment(_M_node);
......@@ -280,14 +280,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
_Self&
operator--()
operator--() _GLIBCXX_NOEXCEPT
{
_M_node = _Rb_tree_decrement(_M_node);
return *this;
}
_Self
operator--(int)
operator--(int) _GLIBCXX_NOEXCEPT
{
_Self __tmp = *this;
_M_node = _Rb_tree_decrement(_M_node);
......@@ -295,11 +295,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
bool
operator==(const _Self& __x) const
operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
{ return _M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
{ return _M_node != __x._M_node; }
_Base_ptr _M_node;
......@@ -308,13 +308,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Val>
inline bool
operator==(const _Rb_tree_iterator<_Val>& __x,
const _Rb_tree_const_iterator<_Val>& __y)
const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node == __y._M_node; }
template<typename _Val>
inline bool
operator!=(const _Rb_tree_iterator<_Val>& __x,
const _Rb_tree_const_iterator<_Val>& __y)
const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node != __y._M_node; }
void
......@@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _M_impl._Node_allocator::allocate(1); }
void
_M_put_node(_Link_type __p)
_M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
{ _M_impl._Node_allocator::deallocate(__p, 1); }
#if __cplusplus < 201103L
......@@ -416,7 +416,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
void
_M_destroy_node(_Link_type __p)
_M_destroy_node(_Link_type __p) noexcept
{
_M_get_Node_allocator().destroy(__p);
_M_put_node(__p);
......@@ -474,46 +474,46 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
protected:
_Base_ptr&
_M_root()
_M_root() _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_parent; }
_Const_Base_ptr
_M_root() const
_M_root() const _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_parent; }
_Base_ptr&
_M_leftmost()
_M_leftmost() _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_left; }
_Const_Base_ptr
_M_leftmost() const
_M_leftmost() const _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_left; }
_Base_ptr&
_M_rightmost()
_M_rightmost() _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_right; }
_Const_Base_ptr
_M_rightmost() const
_M_rightmost() const _GLIBCXX_NOEXCEPT
{ return this->_M_impl._M_header._M_right; }
_Link_type
_M_begin()
_M_begin() _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
_Const_Link_type
_M_begin() const
_M_begin() const _GLIBCXX_NOEXCEPT
{
return static_cast<_Const_Link_type>
(this->_M_impl._M_header._M_parent);
}
_Link_type
_M_end()
_M_end() _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(&this->_M_impl._M_header); }
_Const_Link_type
_M_end() const
_M_end() const _GLIBCXX_NOEXCEPT
{ return static_cast<_Const_Link_type>(&this->_M_impl._M_header); }
static const_reference
......@@ -525,19 +525,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _KeyOfValue()(_S_value(__x)); }
static _Link_type
_S_left(_Base_ptr __x)
_S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(__x->_M_left); }
static _Const_Link_type
_S_left(_Const_Base_ptr __x)
_S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return static_cast<_Const_Link_type>(__x->_M_left); }
static _Link_type
_S_right(_Base_ptr __x)
_S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(__x->_M_right); }
static _Const_Link_type
_S_right(_Const_Base_ptr __x)
_S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return static_cast<_Const_Link_type>(__x->_M_right); }
static const_reference
......@@ -549,19 +549,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _KeyOfValue()(_S_value(__x)); }
static _Base_ptr
_S_minimum(_Base_ptr __x)
_S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return _Rb_tree_node_base::_S_minimum(__x); }
static _Const_Base_ptr
_S_minimum(_Const_Base_ptr __x)
_S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return _Rb_tree_node_base::_S_minimum(__x); }
static _Base_ptr
_S_maximum(_Base_ptr __x)
_S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return _Rb_tree_node_base::_S_maximum(__x); }
static _Const_Base_ptr
_S_maximum(_Const_Base_ptr __x)
_S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return _Rb_tree_node_base::_S_maximum(__x); }
public:
......
......@@ -70,6 +70,7 @@ namespace __gnu_debug
// 21.3.1 construct/copy/destroy:
explicit basic_string(const _Allocator& __a = _Allocator())
_GLIBCXX_NOEXCEPT
: _Base(__a)
{ }
......@@ -238,7 +239,7 @@ namespace __gnu_debug
#if __cplusplus >= 201103L
void
shrink_to_fit()
shrink_to_fit() noexcept
{
if (capacity() > size())
{
......@@ -267,7 +268,7 @@ namespace __gnu_debug
// 21.3.4 element access:
const_reference
operator[](size_type __pos) const
operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
{
_GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
_M_message(__gnu_debug::__msg_subscript_oob)
......@@ -278,7 +279,7 @@ namespace __gnu_debug
}
reference
operator[](size_type __pos)
operator[](size_type __pos) _GLIBCXX_NOEXCEPT
{
#ifdef _GLIBCXX_DEBUG_PEDANTIC
__glibcxx_check_subscript(__pos);
......@@ -582,7 +583,7 @@ namespace __gnu_debug
#if __cplusplus >= 201103L
void
pop_back()
pop_back() noexcept
{
__glibcxx_check_nonempty();
_Base::pop_back();
......
......@@ -98,7 +98,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// NB: _M_limit doesn't check for a bad __pos value.
size_type
_M_limit(size_type __pos, size_type __off) const
_M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
{
const bool __testoff = __off < this->size() - __pos;
return __testoff ? __off : this->size() - __pos;
......@@ -106,7 +106,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// True if _Rep and source do not overlap.
bool
_M_disjunct(const _CharT* __s) const
_M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
{
return (std::less<const _CharT*>()(__s, this->_M_data())
|| std::less<const _CharT*>()(this->_M_data()
......@@ -116,11 +116,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// For the internal use we have functions similar to `begin'/`end'
// but they do not call _M_leak.
iterator
_M_ibegin() const
_M_ibegin() const _GLIBCXX_NOEXCEPT
{ return iterator(this->_M_data()); }
iterator
_M_iend() const
_M_iend() const _GLIBCXX_NOEXCEPT
{ return iterator(this->_M_data() + this->_M_length()); }
public:
......@@ -129,16 +129,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// arguments, per 17.4.4.4 para. 2 item 2.
/**
* @brief Default constructor creates an empty string.
*/
__versa_string()
: __vstring_base() { }
/**
* @brief Construct an empty string using allocator @a a.
*/
explicit
__versa_string(const _Alloc& __a)
__versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
: __vstring_base(__a) { }
// NB: per LWG issue 42, semantics different from IS:
......@@ -269,7 +263,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* copying). @a __str is a valid, but unspecified string.
*/
__versa_string&
operator=(__versa_string&& __str)
operator=(__versa_string&& __str) noexcept
{
// NB: DR 1204.
this->swap(__str);
......@@ -470,7 +464,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
/// A non-binding request to reduce capacity() to size().
void
shrink_to_fit()
shrink_to_fit() noexcept
{
if (capacity() > size())
{
......@@ -538,7 +532,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* see at().)
*/
const_reference
operator[] (size_type __pos) const
operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
{
_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
return this->_M_data()[__pos];
......@@ -555,7 +549,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* see at().) Unshares the string.
*/
reference
operator[](size_type __pos)
operator[](size_type __pos) _GLIBCXX_NOEXCEPT
{
// Allow pos == size() both in C++98 mode, as v3 extension,
// and in C++11 mode.
......@@ -611,7 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* element of the %string.
*/
reference
front()
front() _GLIBCXX_NOEXCEPT
{ return operator[](0); }
/**
......@@ -619,7 +613,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* element of the %string.
*/
const_reference
front() const
front() const _GLIBCXX_NOEXCEPT
{ return operator[](0); }
/**
......@@ -627,7 +621,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* element of the %string.
*/
reference
back()
back() _GLIBCXX_NOEXCEPT
{ return operator[](this->size() - 1); }
/**
......@@ -635,7 +629,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* last element of the %string.
*/
const_reference
back() const
back() const _GLIBCXX_NOEXCEPT
{ return operator[](this->size() - 1); }
#endif
......@@ -814,7 +808,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @a __str is a valid, but unspecified string.
*/
__versa_string&
assign(__versa_string&& __str)
assign(__versa_string&& __str) noexcept
{
this->swap(__str);
return *this;
......@@ -1631,7 +1625,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* constant time.
*/
void
swap(__versa_string& __s)
swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
{ this->_M_swap(__s); }
// String operations:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment