1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <unordered_set>
10
11 // Call erase(const_iterator position) with invalid iterators
12
13 // REQUIRES: has-unix-headers
14 // UNSUPPORTED: !libcpp-has-legacy-debug-mode, c++03
15
16 #include <unordered_set>
17
18 #include "check_assertion.h"
19
main(int,char **)20 int main(int, char**) {
21 // With end()
22 {
23 int a1[] = {1, 2, 3};
24 std::unordered_set<int> l1(a1, a1+3);
25 std::unordered_set<int>::const_iterator i = l1.end();
26 TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i),
27 "unordered container erase(iterator) called with a non-dereferenceable iterator");
28 }
29
30 // With iterator from another container
31 {
32 int a1[] = {1, 2, 3};
33 std::unordered_set<int> l1(a1, a1+3);
34 std::unordered_set<int> l2(a1, a1+3);
35 std::unordered_set<int>::const_iterator i = l2.begin();
36 TEST_LIBCPP_ASSERT_FAILURE(
37 l1.erase(i), "unordered container erase(iterator) called with an iterator not referring to this container");
38 }
39
40 return 0;
41 }
42