Debian Codegraph @

libstdc++-v3/testsuite/20_util/polymorphic_allocator/select.cc

raw
1 // Copyright (C) 2018-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 // { dg-do run { target c++17 } }
19 // { dg-skip-if "" { *-*-* } { -fno-aligned-new } }
20
21 #include <memory_resource>
22 #include <testsuite_allocator.h>
23
24 struct X { int i = 0; };
25
26 using test_type = std::pmr::polymorphic_allocator<X>;
27
28 void
29 test01()
30 {
31 test_type a, b;
32 VERIFY( a.select_on_container_copy_construction() == a );
33 VERIFY( a.select_on_container_copy_construction() == b );
34
35 __gnu_test::memory_resource r;
36 test_type c(&r);
37 VERIFY( c.select_on_container_copy_construction() != c );
38 VERIFY( c.select_on_container_copy_construction() == a );
39 }
40
41 void
42 test02()
43 {
44 __gnu_test::memory_resource r;
45 test_type a(&r);
46 VERIFY( a.select_on_container_copy_construction() != a );
47 std::pmr::set_default_resource(&r);
48 VERIFY( a.select_on_container_copy_construction() == a );
49 std::pmr::set_default_resource(nullptr);
50 }
51
52 int
53 main()
54 {
55 test01();
56 test02();
57 }