]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | // Copyright (C) 2017-2024 Free Software Foundation, Inc. |
676c4146 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-do run { target c++11 } } | |
19 | ||
20 | #include <unordered_map> | |
21 | #include <testsuite_hooks.h> | |
22 | #include <testsuite_allocator.h> | |
23 | ||
24 | struct fails_on_copy { | |
25 | fails_on_copy() = default; | |
26 | fails_on_copy(const fails_on_copy&) { throw 0; }; | |
27 | }; | |
28 | ||
78ed0f80 | 29 | using value_type = std::pair<const int, fails_on_copy>; |
676c4146 JW |
30 | |
31 | void | |
32 | test01() | |
33 | { | |
34 | value_type p; | |
35 | try | |
36 | { | |
37 | std::unordered_map<int, fails_on_copy> umap(&p, &p + 1); | |
38 | } | |
39 | catch(...) | |
40 | { } | |
41 | } | |
42 | ||
43 | void | |
44 | test02() | |
45 | { | |
46 | using Alloc = __gnu_test::tracker_allocator<value_type>; | |
47 | using std::hash; | |
48 | using std::equal_to; | |
49 | ||
50 | value_type p; | |
51 | try | |
52 | { | |
53 | std::unordered_map<int, fails_on_copy, hash<int>, equal_to<int>, Alloc> | |
54 | umap(&p, &p + 1); | |
55 | } | |
56 | catch(...) | |
57 | { } | |
58 | ||
59 | using counter = __gnu_test::tracker_allocator_counter; | |
60 | VERIFY(counter::get_allocation_count() == counter::get_deallocation_count()); | |
61 | } | |
62 | ||
63 | int | |
64 | main() | |
65 | { | |
66 | test01(); | |
67 | test02(); | |
68 | } |