[libc++] Use _LIBCPP_DEBUG_ASSERT in __iterator/wrap_iter.h

Use `_LIBCPP_DEBUG_ASSERT` in `__iterator/wrap_iter.h`

Reviewed By: #libc, Quuxplusone, Mordante, ldionne

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116347
This commit is contained in:
Nikolas Klauser 2022-01-04 15:56:49 +01:00
parent 685c94c6cb
commit 93746b940a
1 changed files with 18 additions and 45 deletions

View File

@ -86,29 +86,20 @@ public:
#endif #endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
if (!__libcpp_is_constant_evaluated()) "Attempted to dereference a non-dereferenceable iterator");
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator");
#endif
return *__i; return *__i;
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
if (!__libcpp_is_constant_evaluated()) "Attempted to dereference a non-dereferenceable iterator");
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator");
#endif
return _VSTD::__to_address(__i); return _VSTD::__to_address(__i);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator++() _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator++() _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
if (!__libcpp_is_constant_evaluated()) "Attempted to increment a non-incrementable iterator");
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment a non-incrementable iterator");
#endif
++__i; ++__i;
return *this; return *this;
} }
@ -117,11 +108,8 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator--() _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator--() _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
if (!__libcpp_is_constant_evaluated()) "Attempted to decrement a non-decrementable iterator");
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement a non-decrementable iterator");
#endif
--__i; --__i;
return *this; return *this;
} }
@ -131,11 +119,8 @@ public:
{__wrap_iter __w(*this); __w += __n; return __w;} {__wrap_iter __w(*this); __w += __n; return __w;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator+=(difference_type __n) _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__addable(this, __n),
if (!__libcpp_is_constant_evaluated()) "Attempted to add/subtract an iterator outside its valid range");
_LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
"Attempted to add/subtract an iterator outside its valid range");
#endif
__i += __n; __i += __n;
return *this; return *this;
} }
@ -145,11 +130,8 @@ public:
{*this += -__n; return *this;} {*this += -__n; return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__subscriptable(this, __n),
if (!__libcpp_is_constant_evaluated()) "Attempted to subscript an iterator outside its valid range");
_LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
"Attempted to subscript an iterator outside its valid range");
#endif
return __i[__n]; return __i[__n];
} }
@ -190,11 +172,8 @@ template <class _Iter1>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
if (!__libcpp_is_constant_evaluated()) "Attempted to compare incomparable iterators");
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
"Attempted to compare incomparable iterators");
#endif
return __x.base() < __y.base(); return __x.base() < __y.base();
} }
@ -202,11 +181,8 @@ template <class _Iter1, class _Iter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
if (!__libcpp_is_constant_evaluated()) "Attempted to compare incomparable iterators");
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
"Attempted to compare incomparable iterators");
#endif
return __x.base() < __y.base(); return __x.base() < __y.base();
} }
@ -276,11 +252,8 @@ typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
#endif // C++03 #endif // C++03
{ {
#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
if (!__libcpp_is_constant_evaluated()) "Attempted to subtract incompatible iterators");
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
"Attempted to subtract incompatible iterators");
#endif
return __x.base() - __y.base(); return __x.base() - __y.base();
} }