[libcxx-commits] [libcxx] [libc++] Add some _LIBCPP_ASSUMEs for bounded iterators (PR #109033)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 28 11:21:27 PST 2024


================
@@ -611,6 +611,10 @@ class _LIBCPP_TEMPLATE_VIS vector {
 
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {
 #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
+    // `__bounded_iter` will tell the compiler that `__p` is bounded by `__begin_` and `__end_cap`, but nothing a priori
+    // relates `__p` to `__end_`.
+    _LIBCPP_ASSUME(__p <= this->__end_);
----------------
ldionne wrote:

I feel like there should also be a `_LIBCPP_ASSERT_INTERNAL` that validates this assumption. Those are only enabled in debug mode, but something's *very* wrong if it doesn't hold.

In general, I think that all `_LIBCPP_ASSUME`s should be accompanied by a corresponding `_LIBCPP_ASSERT_FOO`.

https://github.com/llvm/llvm-project/pull/109033


More information about the libcxx-commits mailing list