| 1 | // Copyright (C) 2013-2025 Free Software Foundation, Inc. |
| 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 | // This test fails to compile since C++17 (see xfail-if below) so we can only |
| 19 | // do a "run" test for C++11 and C++14, and a "compile" test for C++17 and up. |
| 20 | // { dg-do run { target { c++11_only || c++14_only } } } |
| 21 | // { dg-do compile { target c++17 } } |
| 22 | |
| 23 | #include <unordered_set> |
| 24 | #include <memory> |
| 25 | #include <testsuite_hooks.h> |
| 26 | #include <testsuite_allocator.h> |
| 27 | |
| 28 | struct T { int i; }; |
| 29 | bool operator==(const T& l, const T& r) { return l.i == r.i; } |
| 30 | struct H { std::size_t operator()(const T& t) const noexcept { return t.i; } |
| 31 | }; |
| 32 | struct E : std::equal_to<T> { }; |
| 33 | |
| 34 | using __gnu_test::CustomPointerAlloc; |
| 35 | |
| 36 | // { dg-xfail-if "node reinsertion assumes raw pointers" { c++17 } } |
| 37 | // TODO when removing this xfail change the test back to "dg-do run". |
| 38 | template class std::unordered_set<T, H, E, CustomPointerAlloc<T>>; |
| 39 | |
| 40 | void test01() |
| 41 | { |
| 42 | typedef CustomPointerAlloc<T> alloc_type; |
| 43 | typedef std::unordered_set<T, H, E, alloc_type> test_type; |
| 44 | test_type v; |
| 45 | v.insert(T()); |
| 46 | VERIFY( ++v.begin() == v.end() ); |
| 47 | } |
| 48 | |
| 49 | int main() |
| 50 | { |
| 51 | test01(); |
| 52 | } |