]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unsynchronized_pool_resource/cons.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unsynchronized_pool_resource / cons.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
21 #include <memory_resource>
22 #include <testsuite_hooks.h>
23 #include <testsuite_allocator.h>
24
25 void
26 test01()
27 {
28 __gnu_test::memory_resource test_mr1, test_mr2;
29 __gnu_test::default_resource_mgr mgr(&test_mr1);
30
31 const std::pmr::pool_options opts{1, 2};
32 using std::pmr::unsynchronized_pool_resource;
33
34 unsynchronized_pool_resource p1 = {opts, &test_mr2};
35 VERIFY( p1.upstream_resource() == &test_mr2 );
36 unsynchronized_pool_resource p2;
37 VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() );
38 unsynchronized_pool_resource p3{&test_mr2};
39 VERIFY( p3.upstream_resource() == &test_mr2 );
40 unsynchronized_pool_resource p4{opts};
41 VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() );
42
43 static_assert(!std::is_copy_constructible_v<unsynchronized_pool_resource>);
44 static_assert(!std::is_copy_assignable_v<unsynchronized_pool_resource>);
45 static_assert(std::is_destructible_v<unsynchronized_pool_resource>);
46 }
47
48 void
49 test02()
50 {
51 __gnu_test::memory_resource test_mr1, test_mr2;
52 __gnu_test::default_resource_mgr mgr(&test_mr1);
53
54 const std::pmr::pool_options opts{1, 2};
55
56 struct derived : std::pmr::unsynchronized_pool_resource
57 {
58 using unsynchronized_pool_resource::unsynchronized_pool_resource;
59 };
60
61 derived p1 = {opts, &test_mr2};
62 VERIFY( p1.upstream_resource() == &test_mr2 );
63 derived p2;
64 VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() );
65 derived p3{&test_mr2};
66 VERIFY( p3.upstream_resource() == &test_mr2 );
67 derived p4{opts};
68 VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() );
69
70 static_assert(!std::is_copy_constructible_v<derived>);
71 static_assert(!std::is_copy_assignable_v<derived>);
72 static_assert(std::is_destructible_v<derived>);
73 }
74
75 int
76 main()
77 {
78 test01();
79 test02();
80 }