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 <string>
18 #include <unordered_map>
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_multimap<int, std::string> C;
26     C c;
27     c.insert(std::make_pair(1, "one"));
28     C::iterator i = c.end();
29     TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable unordered container iterator");
30     C::const_iterator i2 = c.cend();
31     TEST_LIBCPP_ASSERT_FAILURE(
32         *i2, "Attempted to dereference a non-dereferenceable unordered container const_iterator");
33   }
34 
35   {
36     typedef std::unordered_multimap<int,
37                                     std::string,
38                                     std::hash<int>,
39                                     std::equal_to<int>,
40                                     min_allocator<std::pair<const int, std::string>>>
41         C;
42     C c;
43     c.insert(std::make_pair(1, "one"));
44     C::iterator i = c.end();
45     TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable unordered container iterator");
46     C::const_iterator i2 = c.cend();
47     TEST_LIBCPP_ASSERT_FAILURE(
48         *i2, "Attempted to dereference a non-dereferenceable unordered container const_iterator");
49   }
50 
51   return 0;
52 }
53