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