Explicitly link with libatomic when needed.
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / polymorphic_allocator / construct_pair.cc
blob65398d4c94fde306f2e69244bc6df71bbc60d318
1 // Copyright (C) 2016-2020 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.
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.
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/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
21 #include <memory_resource>
22 #include <utility>
23 #include <tuple>
25 struct do_not_copy {
26 do_not_copy() = default;
27 do_not_copy(const do_not_copy&) { throw 1; }
30 void
31 test01()
33 struct X {
34 X(do_not_copy&&) { }
37 using pair = std::pair<X, int>;
38 std::pmr::polymorphic_allocator<pair> a;
39 auto ptr = a.allocate(1);
40 a.construct(ptr, std::piecewise_construct,
41 std::tuple<do_not_copy>{}, std::make_tuple(1));
42 a.deallocate(ptr, 1);
45 void
46 test02()
48 struct X {
49 using allocator_type = std::pmr::polymorphic_allocator<int>;
50 X(do_not_copy&&, const allocator_type&) { }
53 using pair = std::pair<X, int>;
54 std::pmr::polymorphic_allocator<pair> a;
55 auto ptr = a.allocate(1);
56 a.construct(ptr, std::piecewise_construct,
57 std::tuple<do_not_copy>{}, std::make_tuple(1));
58 a.deallocate(ptr, 1);
61 void
62 test03()
64 struct X {
65 using allocator_type = std::pmr::polymorphic_allocator<int>;
66 X(std::allocator_arg_t, const allocator_type&, do_not_copy&&) { }
69 using pair = std::pair<X, int>;
70 std::pmr::polymorphic_allocator<pair> a;
71 auto ptr = a.allocate(1);
72 a.construct(ptr, std::piecewise_construct,
73 std::tuple<do_not_copy>{}, std::make_tuple(1));
74 a.deallocate(ptr, 1);
77 void
78 test04()
80 struct X
82 using allocator_type = std::pmr::polymorphic_allocator<int>;
83 X() = default;
84 X(const X&) { throw 1; }
85 X(const X&, const allocator_type&) { }
88 struct Y
90 using allocator_type = std::pmr::polymorphic_allocator<int>;
91 Y() = default;
92 Y(const Y&) = delete;
93 Y(std::allocator_arg_t, const allocator_type&, const Y&) { }
96 using pair_type = std::pair<X, Y>;
97 std::pmr::polymorphic_allocator<pair_type> a;
98 auto ptr = a.allocate(1);
99 /* not const */ pair_type p;
100 a.construct(ptr, p); // LWG 2975
101 a.deallocate(ptr, 1);
104 int main()
106 test01();
107 test02();
108 test03();
109 test04();