[libcxx-commits] [libcxx] [libc++] Assert that the position passed to insert and emplace is in [begin(), end()] (PR #230490)

Ilyas Mallah via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 13 03:21:52 PDT 2026


================
@@ -453,6 +453,11 @@ class _LIBCPP_WARN_UNUSED vector<bool, _Allocator> {
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
   __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
 
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
+  __is_valid_insert_position(const_iterator __position) const _NOEXCEPT {
+    return begin() <= __position && __position <= end();
----------------
ilyas-mallah wrote:

Done in 862260a705. In constant evaluation a position from another vector now reaches the assertion, where it used to stop on clang's unrelated-objects note. I added a test for a full vector and a constexpr check that every valid position is accepted.

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


More information about the libcxx-commits mailing list