| 1 | // { dg-do run { target c++17 } } |
| 2 | // { dg-require-effective-target std_allocator_new } |
| 3 | // { dg-xfail-run-if "AIX operator new" { powerpc-ibm-aix* } } |
| 4 | |
| 5 | // Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 6 | // |
| 7 | // This file is part of the GNU ISO C++ Library. This library is free |
| 8 | // software; you can redistribute it and/or modify it under the |
| 9 | // terms of the GNU General Public License as published by the |
| 10 | // Free Software Foundation; either version 3, or (at your option) |
| 11 | // any later version. |
| 12 | |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | |
| 18 | // You should have received a copy of the GNU General Public License along |
| 19 | // with this library; see the file COPYING3. If not see |
| 20 | // <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | // libstdc++/96088 |
| 23 | |
| 24 | #include <string_view> |
| 25 | #include <string> |
| 26 | #include <unordered_map> |
| 27 | |
| 28 | #include <testsuite_hooks.h> |
| 29 | #include <replacement_memory_operators.h> |
| 30 | |
| 31 | static constexpr std::initializer_list<std::pair<const char*, const char*>> lst = |
| 32 | { { "long_str_for_dynamic_allocation", "long_str_for_dynamic_allocation" } }; |
| 33 | |
| 34 | void |
| 35 | test01() |
| 36 | { |
| 37 | __gnu_test::counter::reset(); |
| 38 | std::unordered_multimap<std::string, std::string, |
| 39 | std::hash<std::string_view>, |
| 40 | std::equal_to<std::string_view>> foo; |
| 41 | foo.insert(lst.begin(), lst.end()); |
| 42 | VERIFY( foo.size() == 1 ); |
| 43 | |
| 44 | VERIFY( __gnu_test::counter::count() == 4 ); |
| 45 | VERIFY( __gnu_test::counter::get()._M_increments == 4 ); |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | test02() |
| 50 | { |
| 51 | __gnu_test::counter::reset(); |
| 52 | std::unordered_multimap<std::string, std::string> foo; |
| 53 | foo.insert(lst.begin(), lst.end()); |
| 54 | VERIFY( foo.size() == 1 ); |
| 55 | |
| 56 | VERIFY( __gnu_test::counter::count() == 4 ); |
| 57 | VERIFY( __gnu_test::counter::get()._M_increments == 4 ); |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | main() |
| 62 | { |
| 63 | __gnu_test::counter::scope s; |
| 64 | test01(); |
| 65 | test02(); |
| 66 | return 0; |
| 67 | } |