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