[libcxx-commits] [libcxx] 93746b9 - [libc++] Use _LIBCPP_DEBUG_ASSERT in __iterator/wrap_iter.h
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 5 00:17:02 PST 2022
Author: Nikolas Klauser
Date: 2022-01-05T09:15:42+01:00
New Revision: 93746b940aea0c7cee144b8de49080e83528b1b9
URL: https://github.com/llvm/llvm-project/commit/93746b940aea0c7cee144b8de49080e83528b1b9
DIFF: https://github.com/llvm/llvm-project/commit/93746b940aea0c7cee144b8de49080e83528b1b9.diff
LOG: [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
Added:
Modified:
libcxx/include/__iterator/wrap_iter.h
Removed:
################################################################################
diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 5a386eec4b227..1408c673bc610 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -86,29 +86,20 @@ class __wrap_iter
#endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
- "Attempted to dereference a non-dereferenceable iterator");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+ "Attempted to dereference a non-dereferenceable iterator");
return *__i;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
- "Attempted to dereference a non-dereferenceable iterator");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+ "Attempted to dereference a non-dereferenceable iterator");
return _VSTD::__to_address(__i);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator++() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
- "Attempted to increment a non-incrementable iterator");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+ "Attempted to increment a non-incrementable iterator");
++__i;
return *this;
}
@@ -117,11 +108,8 @@ class __wrap_iter
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator--() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
- "Attempted to decrement a non-decrementable iterator");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
+ "Attempted to decrement a non-decrementable iterator");
--__i;
return *this;
}
@@ -131,11 +119,8 @@ class __wrap_iter
{__wrap_iter __w(*this); __w += __n; return __w;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator+=(
diff erence_type __n) _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
- "Attempted to add/subtract an iterator outside its valid range");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__addable(this, __n),
+ "Attempted to add/subtract an iterator outside its valid range");
__i += __n;
return *this;
}
@@ -145,11 +130,8 @@ class __wrap_iter
{*this += -__n; return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](
diff erence_type __n) const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
- "Attempted to subscript an iterator outside its valid range");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__subscriptable(this, __n),
+ "Attempted to subscript an iterator outside its valid range");
return __i[__n];
}
@@ -190,11 +172,8 @@ template <class _Iter1>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
- "Attempted to compare incomparable iterators");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
+ "Attempted to compare incomparable iterators");
return __x.base() < __y.base();
}
@@ -202,11 +181,8 @@ template <class _Iter1, class _Iter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
- "Attempted to compare incomparable iterators");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
+ "Attempted to compare incomparable iterators");
return __x.base() < __y.base();
}
@@ -276,11 +252,8 @@ typename __wrap_iter<_Iter1>::
diff erence_type
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
#endif // C++03
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
- "Attempted to subtract incompatible iterators");
-#endif
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
+ "Attempted to subtract incompatible iterators");
return __x.base() - __y.base();
}
More information about the libcxx-commits
mailing list