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_map>
10
11 // Dereference non-dereferenceable iterator.
12
13 // REQUIRES: has-unix-headers, libcpp-hardening-mode={{extensive|debug}}
14 // UNSUPPORTED: c++03
15 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
16
17 #include <unordered_map>
18 #include <string>
19
20 #include "check_assertion.h"
21 #include "min_allocator.h"
22
main(int,char **)23 int main(int, char**) {
24 {
25 typedef std::unordered_map<int, std::string> C;
26 C c(1);
27 C::local_iterator i = c.end(0);
28 TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable unordered container local_iterator");
29 C::const_local_iterator i2 = c.cend(0);
30 TEST_LIBCPP_ASSERT_FAILURE(
31 *i2, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
32 }
33
34 {
35 typedef std::unordered_map<int,
36 std::string,
37 std::hash<int>,
38 std::equal_to<int>,
39 min_allocator<std::pair<const int, std::string>>>
40 C;
41 C c(1);
42 C::local_iterator i = c.end(0);
43 TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable unordered container local_iterator");
44 C::const_local_iterator i2 = c.cend(0);
45 TEST_LIBCPP_ASSERT_FAILURE(
46 *i2, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
47 }
48
49 return 0;
50 }
51