| 1 |
// Copyright (C) 2016-2025 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++11 } } |
| 19 |
// { dg-require-effective-target hosted } |
| 20 |
|
| 21 |
#include <utility> |
| 22 |
#include <tuple> |
| 23 |
#include <scoped_allocator> |
| 24 |
|
| 25 |
struct do_not_copy { |
| 26 |
do_not_copy() = default; |
| 27 |
do_not_copy(const do_not_copy&) { throw 1; } |
| 28 |
}; |
| 29 |
|
| 30 |
void |
| 31 |
test01() |
| 32 |
{ |
| 33 |
struct X { |
| 34 |
X(do_not_copy&&) { } |
| 35 |
}; |
| 36 |
|
| 37 |
using pair = std::pair<X, int>; |
| 38 |
std::scoped_allocator_adaptor<std::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); |
| 43 |
} |
| 44 |
|
| 45 |
void |
| 46 |
test02() |
| 47 |
{ |
| 48 |
struct X { |
| 49 |
using allocator_type = std::allocator<int>; |
| 50 |
X(do_not_copy&&, const allocator_type&) { } |
| 51 |
}; |
| 52 |
|
| 53 |
using pair = std::pair<X, int>; |
| 54 |
std::scoped_allocator_adaptor<std::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); |
| 59 |
} |
| 60 |
|
| 61 |
void |
| 62 |
test03() |
| 63 |
{ |
| 64 |
struct X { |
| 65 |
using allocator_type = std::allocator<int>; |
| 66 |
X(std::allocator_arg_t, const allocator_type&, do_not_copy&&) { } |
| 67 |
}; |
| 68 |
|
| 69 |
using pair = std::pair<X, int>; |
| 70 |
std::scoped_allocator_adaptor<std::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); |
| 75 |
} |
| 76 |
|
| 77 |
void |
| 78 |
test04() |
| 79 |
{ |
| 80 |
struct X |
| 81 |
{ |
| 82 |
using allocator_type = std::allocator<int>; |
| 83 |
X() = default; |
| 84 |
X(const X&) { throw 1; } |
| 85 |
X(const X&, const allocator_type&) { } |
| 86 |
}; |
| 87 |
|
| 88 |
struct Y |
| 89 |
{ |
| 90 |
using allocator_type = std::allocator<int>; |
| 91 |
Y() = default; |
| 92 |
Y(const Y&) = delete; |
| 93 |
Y(std::allocator_arg_t, const allocator_type&, const Y&) { } |
| 94 |
}; |
| 95 |
|
| 96 |
using pair_type = std::pair<X, Y>; |
| 97 |
std::scoped_allocator_adaptor<std::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); |
| 102 |
} |
| 103 |
|
| 104 |
int main() |
| 105 |
{ |
| 106 |
test01(); |
| 107 |
test02(); |
| 108 |
test03(); |
| 109 |
test04(); |
| 110 |
} |