| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-require-effective-target hosted } |
| 3 | |
| 4 | // Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 5 | // |
| 6 | // This file is part of the GNU ISO C++ Library. This library is free |
| 7 | // software; you can redistribute it and/or modify it under the |
| 8 | // terms of the GNU General Public License as published by the |
| 9 | // Free Software Foundation; either version 3, or (at your option) |
| 10 | // any later version. |
| 11 | |
| 12 | // This library is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | |
| 17 | // You should have received a copy of the GNU General Public License along |
| 18 | // with this library; see the file COPYING3. If not see |
| 19 | // <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | #include <tuple> |
| 22 | #include <type_traits> |
| 23 | #include <memory> |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | template<typename T> |
| 27 | typename std::decay<T>::type copy(T&& x) |
| 28 | { return std::forward<T>(x); } |
| 29 | |
| 30 | // libstdc++/48476 |
| 31 | void test01() |
| 32 | { |
| 33 | std::shared_ptr<int> p(new int()), q, r; |
| 34 | |
| 35 | std::tuple<std::shared_ptr<int>&, int> t0(p, 23), t1(q, 0); |
| 36 | t1 = copy(t0); // shall be equivalent to |
| 37 | // q = p; std::get<1>(t1) = std::get<1>(t0); |
| 38 | VERIFY( q == p ); |
| 39 | |
| 40 | std::tuple<std::shared_ptr<int>&, char> t2(r, 0); |
| 41 | t2 = copy(t1); // shall be equivalent to |
| 42 | // r = q; std::get<1>(t2) = std::get<1>(t1); |
| 43 | VERIFY( r == q ); |
| 44 | } |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | test01(); |
| 49 | return 0; |
| 50 | } |