]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/polymorphic_allocator/construct_pair.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / polymorphic_allocator / construct_pair.cc
1 // Copyright (C) 2016-2022 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
20 #include <memory_resource>
21 #include <utility>
22 #include <tuple>
23
24 struct do_not_copy {
25 do_not_copy() = default;
26 do_not_copy(const do_not_copy&) { throw 1; }
27 };
28
29 void
30 test01()
31 {
32 struct X {
33 X(do_not_copy&&) { }
34 };
35
36 using pair = std::pair<X, int>;
37 std::pmr::polymorphic_allocator<pair> a;
38 auto ptr = a.allocate(1);
39 a.construct(ptr, std::piecewise_construct,
40 std::tuple<do_not_copy>{}, std::make_tuple(1));
41 a.deallocate(ptr, 1);
42 }
43
44 void
45 test02()
46 {
47 struct X {
48 using allocator_type = std::pmr::polymorphic_allocator<int>;
49 X(do_not_copy&&, const allocator_type&) { }
50 };
51
52 using pair = std::pair<X, int>;
53 std::pmr::polymorphic_allocator<pair> a;
54 auto ptr = a.allocate(1);
55 a.construct(ptr, std::piecewise_construct,
56 std::tuple<do_not_copy>{}, std::make_tuple(1));
57 a.deallocate(ptr, 1);
58 }
59
60 void
61 test03()
62 {
63 struct X {
64 using allocator_type = std::pmr::polymorphic_allocator<int>;
65 X(std::allocator_arg_t, const allocator_type&, do_not_copy&&) { }
66 };
67
68 using pair = std::pair<X, int>;
69 std::pmr::polymorphic_allocator<pair> a;
70 auto ptr = a.allocate(1);
71 a.construct(ptr, std::piecewise_construct,
72 std::tuple<do_not_copy>{}, std::make_tuple(1));
73 a.deallocate(ptr, 1);
74 }
75
76 void
77 test04()
78 {
79 struct X
80 {
81 using allocator_type = std::pmr::polymorphic_allocator<int>;
82 X() = default;
83 X(const X&) { throw 1; }
84 X(const X&, const allocator_type&) { }
85 };
86
87 struct Y
88 {
89 using allocator_type = std::pmr::polymorphic_allocator<int>;
90 Y() = default;
91 Y(const Y&) = delete;
92 Y(std::allocator_arg_t, const allocator_type&, const Y&) { }
93 };
94
95 using pair_type = std::pair<X, Y>;
96 std::pmr::polymorphic_allocator<pair_type> a;
97 auto ptr = a.allocate(1);
98 /* not const */ pair_type p;
99 a.construct(ptr, p); // LWG 2975
100 a.deallocate(ptr, 1);
101 }
102
103 int main()
104 {
105 test01();
106 test02();
107 test03();
108 test04();
109 }