| 1 |
// Copyright (C) 2020-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 compile { target c++11 } } |
| 19 |
// FIXME [!HOSTED]: avoidable std::allocator usage |
| 20 |
// { dg-require-effective-target hosted } |
| 21 |
|
| 22 |
#include <tuple> |
| 23 |
#include <memory> |
| 24 |
|
| 25 |
struct X |
| 26 |
{ |
| 27 |
using allocator_type = std::allocator<int>; |
| 28 |
|
| 29 |
X(X&&) { } |
| 30 |
X(std::allocator_arg_t, const allocator_type&, X&&) { } |
| 31 |
|
| 32 |
explicit X(int) { } |
| 33 |
explicit X(int, allocator_type) { } |
| 34 |
}; |
| 35 |
|
| 36 |
void |
| 37 |
test01() |
| 38 |
{ |
| 39 |
// PR libstdc++/96803 |
| 40 |
// std::tuple chooses wrong constructor for uses-allocator construction |
| 41 |
std::tuple<int> o; |
| 42 |
std::tuple<X> nok(std::allocator_arg, std::allocator<int>(), o); |
| 43 |
|
| 44 |
std::tuple<int, int> oo; |
| 45 |
std::tuple<X, X> nn(std::allocator_arg, std::allocator<int>(), oo); |
| 46 |
} |
| 47 |
|
| 48 |
struct Y |
| 49 |
{ |
| 50 |
using allocator_type = std::allocator<int>; |
| 51 |
|
| 52 |
Y(const X&) { } |
| 53 |
Y(const X&, const allocator_type&) { } |
| 54 |
|
| 55 |
Y(X&&) { } |
| 56 |
Y(std::allocator_arg_t, const allocator_type&, X&&) { } |
| 57 |
}; |
| 58 |
|
| 59 |
void |
| 60 |
test02() |
| 61 |
{ |
| 62 |
std::tuple<X, X> o{1, 1}; |
| 63 |
std::tuple<Y, Y> oo(std::allocator_arg, std::allocator<int>(), o); |
| 64 |
} |