LWG 2975 ensure construct(pair<T,U>*, ...) used to construct pairs
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / scoped_allocator / construct_pair.cc
blobb34efc88798279388c6705e28c9ba58f350586f5
1 // Copyright (C) 2016-2018 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-do run { target c++11 } }
20 #include <utility>
21 #include <tuple>
22 #include <scoped_allocator>
24 struct do_not_copy {
25 do_not_copy() = default;
26 do_not_copy(const do_not_copy&) { throw 1; }
29 void
30 test01()
32 struct X {
33 X(do_not_copy&&) { }
36 using pair = std::pair<X, int>;
37 std::scoped_allocator_adaptor<std::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);
44 void
45 test02()
47 struct X {
48 using allocator_type = std::allocator<int>;
49 X(do_not_copy&&, const allocator_type&) { }
52 using pair = std::pair<X, int>;
53 std::scoped_allocator_adaptor<std::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);
60 void
61 test03()
63 struct X {
64 using allocator_type = std::allocator<int>;
65 X(std::allocator_arg_t, const allocator_type&, do_not_copy&&) { }
68 using pair = std::pair<X, int>;
69 std::scoped_allocator_adaptor<std::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);
76 void
77 test04()
79 struct X
81 using allocator_type = std::allocator<int>;
82 X() = default;
83 X(const X&) { throw 1; }
84 X(const X&, const allocator_type&) { }
87 struct Y
89 using allocator_type = std::allocator<int>;
90 Y() = default;
91 Y(const Y&) = delete;
92 Y(std::allocator_arg_t, const allocator_type&, const Y&) { }
95 using pair_type = std::pair<X, Y>;
96 std::scoped_allocator_adaptor<std::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);
103 int main()
105 test01();
106 test02();
107 test03();
108 test04();