Commit d15ac9d9 by Marc Glisse Committed by Marc Glisse

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

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

	PR libstdc++/58338
	* include/bits/allocator.h (__alloc_swap::_S_do_it,
	__shrink_to_fit_aux::_S_do_it): Mark as noexcept.
	* include/bits/basic_string.h (basic_string::_Rep) [_S_empty_rep,
	_M_is_leaked, _M_is_shared, _M_set_leaked, _M_set_sharable,
	_M_set_length_and_sharable, _M_dispose]: Likewise.
	(basic_string::_Alloc_hider::_Alloc_hider): Likewise.
	(basic_string) [_M_data, _M_rep, _M_ibegin, _M_iend, _M_limit,
	_M_disjunct, _M_copy, _M_move, _M_assign, _S_copy_chars, _S_compare,
	_S_empty_rep, shrink_to_fit, operator[] const, front const, back const]:
	Likewise.
	[clear]: Link to PR 56166.
	[swap]: Link to PR 58265.
	* include/bits/stl_deque.h (_Deque_iterator) [_S_buffer_size,
	_Deque_iterator, _M_const_cast, operator*, operator->, operator++,
	operator--, operator+=, operator+, operator-=, operator-, operator[],
	_M_set_node]: Mark as noexcept.
	(operator==(const _Deque_iterator&, const _Deque_iterator&),
	operator!=(const _Deque_iterator&, const _Deque_iterator&),
	operator<(const _Deque_iterator&, const _Deque_iterator&),
	operator>(const _Deque_iterator&, const _Deque_iterator&),
	operator<=(const _Deque_iterator&, const _Deque_iterator&),
	operator>=(const _Deque_iterator&, const _Deque_iterator&),
	operator-(const _Deque_iterator&, const _Deque_iterator&),
	operator+(ptrdiff_t, const _Deque_iterator&)): Likewise.
	(_Deque_base) [_Deque_base(const allocator_type&)]: Add missing call to
	_M_initialize_map.
	[~_Deque_base, _M_deallocate_node, _M_deallocate_map, _M_destroy_nodes]:
	Mark as noexcept.
	(_Deque_base::_Deque_impl) [_Deque_impl(const _Tp_alloc_type&),
	_Deque_impl(_Tp_alloc_type&&)]: Likewise.
	(deque) [_S_buffer_size, operator=(deque&&), shrink_to_fit, operator[],
	front, back, pop_front, pop_back, swap]: Likewise.
	[deque(), deque(const allocator_type&)]: Merge.
	* include/debug/deque (deque) [operator=(deque&&), shrink_to_fit,
	operator[], front, back, pop_front, pop_back, swap]: Mark as noexcept.
	* include/profile/deque (deque) [operator=(deque&&), operator[], front,
	back, pop_front, pop_back, swap]: Likewise.
	* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
	Adjust line number.
	* 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/deque/requirements/dr438/insert_neg.cc:
	Likewise.

From-SVN: r202781
parent d20e48b0
2013-09-20 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/58338
* include/bits/allocator.h (__alloc_swap::_S_do_it,
__shrink_to_fit_aux::_S_do_it): Mark as noexcept.
* include/bits/basic_string.h (basic_string::_Rep) [_S_empty_rep,
_M_is_leaked, _M_is_shared, _M_set_leaked, _M_set_sharable,
_M_set_length_and_sharable, _M_dispose]: Likewise.
(basic_string::_Alloc_hider::_Alloc_hider): Likewise.
(basic_string) [_M_data, _M_rep, _M_ibegin, _M_iend, _M_limit,
_M_disjunct, _M_copy, _M_move, _M_assign, _S_copy_chars, _S_compare,
_S_empty_rep, shrink_to_fit, operator[] const, front const, back const]:
Likewise.
[clear]: Link to PR 56166.
[swap]: Link to PR 58265.
* include/bits/stl_deque.h (_Deque_iterator) [_S_buffer_size,
_Deque_iterator, _M_const_cast, operator*, operator->, operator++,
operator--, operator+=, operator+, operator-=, operator-, operator[],
_M_set_node]: Mark as noexcept.
(operator==(const _Deque_iterator&, const _Deque_iterator&),
operator!=(const _Deque_iterator&, const _Deque_iterator&),
operator<(const _Deque_iterator&, const _Deque_iterator&),
operator>(const _Deque_iterator&, const _Deque_iterator&),
operator<=(const _Deque_iterator&, const _Deque_iterator&),
operator>=(const _Deque_iterator&, const _Deque_iterator&),
operator-(const _Deque_iterator&, const _Deque_iterator&),
operator+(ptrdiff_t, const _Deque_iterator&)): Likewise.
(_Deque_base) [_Deque_base(const allocator_type&)]: Add missing call to
_M_initialize_map.
[~_Deque_base, _M_deallocate_node, _M_deallocate_map, _M_destroy_nodes]:
Mark as noexcept.
(_Deque_base::_Deque_impl) [_Deque_impl(const _Tp_alloc_type&),
_Deque_impl(_Tp_alloc_type&&)]: Likewise.
(deque) [_S_buffer_size, operator=(deque&&), shrink_to_fit, operator[],
front, back, pop_front, pop_back, swap]: Likewise.
[deque(), deque(const allocator_type&)]: Merge.
* include/debug/deque (deque) [operator=(deque&&), shrink_to_fit,
operator[], front, back, pop_front, pop_back, swap]: Mark as noexcept.
* include/profile/deque (deque) [operator=(deque&&), operator[], front,
back, pop_front, pop_back, swap]: Likewise.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
Adjust line number.
* 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/deque/requirements/dr438/insert_neg.cc:
Likewise.
2013-09-20 Alan Modra <amodra@gmail.com>
* configure: Regenerate.
......
......@@ -158,13 +158,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// To implement Option 3 of DR 431.
template<typename _Alloc, bool = __is_empty(_Alloc)>
struct __alloc_swap
{ static void _S_do_it(_Alloc&, _Alloc&) { } };
{ static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };
template<typename _Alloc>
struct __alloc_swap<_Alloc, false>
{
static void
_S_do_it(_Alloc& __one, _Alloc& __two)
_S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT
{
// Precondition: swappable allocators.
if (__one != __two)
......@@ -194,13 +194,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= __or_<is_copy_constructible<typename _Tp::value_type>,
is_nothrow_move_constructible<typename _Tp::value_type>>::value>
struct __shrink_to_fit_aux
{ static bool _S_do_it(_Tp&) { return false; } };
{ static bool _S_do_it(_Tp&) noexcept { return false; } };
template<typename _Tp>
struct __shrink_to_fit_aux<_Tp, true>
{
static bool
_S_do_it(_Tp& __c)
_S_do_it(_Tp& __c) noexcept
{
__try
{
......
......@@ -178,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static size_type _S_empty_rep_storage[];
static _Rep&
_S_empty_rep()
_S_empty_rep() _GLIBCXX_NOEXCEPT
{
// NB: Mild hack to avoid strict-aliasing warnings. Note that
// _S_empty_rep_storage is never modified and the punning should
......@@ -188,23 +188,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
bool
_M_is_leaked() const
_M_is_leaked() const _GLIBCXX_NOEXCEPT
{ return this->_M_refcount < 0; }
bool
_M_is_shared() const
_M_is_shared() const _GLIBCXX_NOEXCEPT
{ return this->_M_refcount > 0; }
void
_M_set_leaked()
_M_set_leaked() _GLIBCXX_NOEXCEPT
{ this->_M_refcount = -1; }
void
_M_set_sharable()
_M_set_sharable() _GLIBCXX_NOEXCEPT
{ this->_M_refcount = 0; }
void
_M_set_length_and_sharable(size_type __n)
_M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
{
#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
if (__builtin_expect(this != &_S_empty_rep(), false))
......@@ -234,7 +234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_create(size_type, size_type, const _Alloc&);
void
_M_dispose(const _Alloc& __a)
_M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPT
{
#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
if (__builtin_expect(this != &_S_empty_rep(), false))
......@@ -271,7 +271,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Use empty-base optimization: http://www.cantrip.org/emptyopt.html
struct _Alloc_hider : _Alloc
{
_Alloc_hider(_CharT* __dat, const _Alloc& __a)
_Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT
: _Alloc(__a), _M_p(__dat) { }
_CharT* _M_p; // The actual data.
......@@ -289,25 +289,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
mutable _Alloc_hider _M_dataplus;
_CharT*
_M_data() const
_M_data() const _GLIBCXX_NOEXCEPT
{ return _M_dataplus._M_p; }
_CharT*
_M_data(_CharT* __p)
_M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
{ return (_M_dataplus._M_p = __p); }
_Rep*
_M_rep() const
_M_rep() const _GLIBCXX_NOEXCEPT
{ return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
// 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(_M_data()); }
iterator
_M_iend() const
_M_iend() const _GLIBCXX_NOEXCEPT
{ return iterator(_M_data() + this->size()); }
void
......@@ -334,7 +334,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;
......@@ -342,7 +342,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 (less<const _CharT*>()(__s, _M_data())
|| less<const _CharT*>()(_M_data() + this->size(), __s));
......@@ -351,7 +351,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// When __n = 1 way faster than the general multichar
// traits_type::copy/move/assign.
static void
_M_copy(_CharT* __d, const _CharT* __s, size_type __n)
_M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
{
if (__n == 1)
traits_type::assign(*__d, *__s);
......@@ -360,7 +360,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
static void
_M_move(_CharT* __d, const _CharT* __s, size_type __n)
_M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
{
if (__n == 1)
traits_type::assign(*__d, *__s);
......@@ -369,7 +369,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
static void
_M_assign(_CharT* __d, size_type __n, _CharT __c)
_M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
{
if (__n == 1)
traits_type::assign(*__d, __c);
......@@ -382,29 +382,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<class _Iterator>
static void
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
_GLIBCXX_NOEXCEPT
{
for (; __k1 != __k2; ++__k1, ++__p)
traits_type::assign(*__p, *__k1); // These types are off.
}
static void
_S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
_S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
static void
_S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
_GLIBCXX_NOEXCEPT
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
static void
_S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
_S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
{ _M_copy(__p, __k1, __k2 - __k1); }
static void
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
_GLIBCXX_NOEXCEPT
{ _M_copy(__p, __k1, __k2 - __k1); }
static int
_S_compare(size_type __n1, size_type __n2)
_S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
{
const difference_type __d = difference_type(__n1 - __n2);
......@@ -423,7 +426,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_leak_hard();
static _Rep&
_S_empty_rep()
_S_empty_rep() _GLIBCXX_NOEXCEPT
{ return _Rep::_S_empty_rep(); }
public:
......@@ -756,7 +759,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
/// A non-binding request to reduce capacity() to size().
void
shrink_to_fit()
shrink_to_fit() _GLIBCXX_NOEXCEPT
{
if (capacity() > size())
{
......@@ -799,6 +802,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* Erases the string, making it empty.
*/
// PR 56166: this should not throw.
void
clear() _GLIBCXX_NOEXCEPT
{ _M_mutate(0, this->size(), 0); }
......@@ -823,7 +827,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 <= size());
return _M_data()[__pos];
......@@ -903,7 +907,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* element of the %string.
*/
const_reference
front() const
front() const _GLIBCXX_NOEXCEPT
{ return operator[](0); }
/**
......@@ -919,7 +923,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* last element of the %string.
*/
const_reference
back() const
back() const _GLIBCXX_NOEXCEPT
{ return operator[](this->size() - 1); }
#endif
......@@ -1787,6 +1791,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Exchanges the contents of this string with that of @a __s in constant
* time.
*/
// PR 58265, this should be noexcept.
void
swap(basic_string& __s);
......
......@@ -128,7 +128,7 @@ namespace __debug
#if __cplusplus >= 201103L
deque&
operator=(deque&& __x)
operator=(deque&& __x) noexcept
{
// NB: DR 1204.
// NB: DR 675.
......@@ -287,7 +287,7 @@ namespace __debug
#if __cplusplus >= 201103L
void
shrink_to_fit()
shrink_to_fit() noexcept
{
if (_Base::_M_shrink_to_fit())
this->_M_invalidate_all();
......@@ -298,14 +298,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];
......@@ -314,28 +314,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();
......@@ -468,7 +468,7 @@ namespace __debug
#endif
void
pop_front()
pop_front() _GLIBCXX_NOEXCEPT
{
__glibcxx_check_nonempty();
this->_M_invalidate_if(_Equal(_Base::begin()));
......@@ -476,7 +476,7 @@ namespace __debug
}
void
pop_back()
pop_back() _GLIBCXX_NOEXCEPT
{
__glibcxx_check_nonempty();
this->_M_invalidate_if(_Equal(--_Base::end()));
......@@ -556,7 +556,7 @@ namespace __debug
}
void
swap(deque& __x)
swap(deque& __x) _GLIBCXX_NOEXCEPT
{
_Base::swap(__x);
this->_M_swap(__x);
......
......@@ -117,7 +117,7 @@ namespace __profile
#if __cplusplus >= 201103L
deque&
operator=(deque&& __x)
operator=(deque&& __x) noexcept
{
// NB: DR 1204.
// NB: DR 675.
......@@ -245,13 +245,13 @@ namespace __profile
// element access:
reference
operator[](size_type __n)
operator[](size_type __n) _GLIBCXX_NOEXCEPT
{
return _M_base()[__n];
}
const_reference
operator[](size_type __n) const
operator[](size_type __n) const _GLIBCXX_NOEXCEPT
{
return _M_base()[__n];
}
......@@ -259,25 +259,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();
}
......@@ -375,13 +375,13 @@ namespace __profile
#endif
void
pop_front()
pop_front() _GLIBCXX_NOEXCEPT
{
_Base::pop_front();
}
void
pop_back()
pop_back() _GLIBCXX_NOEXCEPT
{
_Base::pop_back();
}
......@@ -409,7 +409,7 @@ namespace __profile
}
void
swap(deque& __x)
swap(deque& __x) _GLIBCXX_NOEXCEPT
{
_Base::swap(__x);
}
......
......@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1760 }
// { dg-error "no matching" "" { target *-*-* } 1755 }
#include <deque>
......
......@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1693 }
// { dg-error "no matching" "" { target *-*-* } 1688 }
#include <deque>
......
......@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1693 }
// { dg-error "no matching" "" { target *-*-* } 1688 }
#include <deque>
#include <utility>
......
......@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1844 }
// { dg-error "no matching" "" { target *-*-* } 1839 }
#include <deque>
......
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