[libcxx-commits] [libcxx] [libc++] Assert that erase and extract are not passed end() in the associative containers (PR #232661)
Ilyas Mallah via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 22 00:07:32 PDT 2026
================
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: can-test-hardening-assertions-fast
+// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
+
+// <set>
+
+// Call erase(const_iterator) and extract(const_iterator) with end().
+
+#include <set>
+
+#include "check_assertion.h"
+
+int main(int, char**) {
+ {
+ int a[] = {1, 2, 3};
+ std::set<int> c(a, a + 3);
+ TEST_LIBCPP_ASSERT_FAILURE(
+ c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
+ TEST_LIBCPP_ASSERT_FAILURE(
+ c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
+ TEST_LIBCPP_ASSERT_FAILURE(
+ c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
+ TEST_LIBCPP_ASSERT_FAILURE(
+ c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
+ }
+
+ {
+ std::set<int> c;
+ TEST_LIBCPP_ASSERT_FAILURE(
+ c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
+ }
+
+ {
+ int a[] = {1, 2, 3};
+ std::multiset<int> c(a, a + 3);
----------------
ilyas-mallah wrote:
The multiset and multimap tests now have their own files under associative/multiset and associative/multimap, in https://github.com/llvm/llvm-project/commit/b4432791c29ef4cec27b6db4f8e860cfad5d807f. The map test had the same mix, so I split it the same way. The blocks are moved unchanged.
https://github.com/llvm/llvm-project/pull/232661
More information about the libcxx-commits
mailing list