| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | #include <string> |
| 21 | #include <tuple> |
| 22 | #include <testsuite_hooks.h> |
| 23 | |
| 24 | static std::string result; |
| 25 | |
| 26 | struct X { |
| 27 | int state; // this has to be here |
| 28 | X() { |
| 29 | result += "Def"; |
| 30 | } |
| 31 | |
| 32 | X(X const&) { |
| 33 | result += "Copy"; |
| 34 | } |
| 35 | |
| 36 | X(X&&) { |
| 37 | result += "Move"; |
| 38 | } |
| 39 | |
| 40 | ~X() { |
| 41 | result += "Dtor"; |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | void f() |
| 46 | { |
| 47 | X v; |
| 48 | std::tuple<X> t1{v}; |
| 49 | std::tuple<std::tuple<X>&&> t2{std::move(t1)}; |
| 50 | std::tuple<std::tuple<X>> t3{std::move(t2)}; |
| 51 | } |
| 52 | |
| 53 | void f2() |
| 54 | { |
| 55 | X v; |
| 56 | std::tuple<X> t1{std::move(v)}; |
| 57 | std::tuple<std::tuple<X>&&> t2{std::move(t1)}; |
| 58 | std::tuple<std::tuple<X>> t3{std::move(t2)}; |
| 59 | } |
| 60 | |
| 61 | void f3() |
| 62 | { |
| 63 | std::tuple<X> t1{X{}}; |
| 64 | std::tuple<std::tuple<X>&&> t2{std::move(t1)}; |
| 65 | std::tuple<std::tuple<X>> t3{std::move(t2)}; |
| 66 | } |
| 67 | |
| 68 | void f4() |
| 69 | { |
| 70 | std::allocator<X> a; |
| 71 | X v; |
| 72 | std::tuple<X> t1{std::allocator_arg, a, v}; |
| 73 | std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)}; |
| 74 | std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)}; |
| 75 | } |
| 76 | |
| 77 | void f5() |
| 78 | { |
| 79 | std::allocator<X> a; |
| 80 | X v; |
| 81 | std::tuple<X> t1{std::allocator_arg, a, std::move(v)}; |
| 82 | std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)}; |
| 83 | std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)}; |
| 84 | } |
| 85 | |
| 86 | void f6() |
| 87 | { |
| 88 | std::allocator<X> a; |
| 89 | std::tuple<X> t1{std::allocator_arg, a, X{}}; |
| 90 | std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)}; |
| 91 | std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)}; |
| 92 | } |
| 93 | |
| 94 | int main() |
| 95 | { |
| 96 | f(); |
| 97 | VERIFY(result == "DefCopyMoveDtorDtorDtor"); |
| 98 | result = ""; |
| 99 | f2(); |
| 100 | VERIFY(result == "DefMoveMoveDtorDtorDtor"); |
| 101 | result = ""; |
| 102 | f3(); |
| 103 | VERIFY(result == "DefMoveDtorMoveDtorDtor"); |
| 104 | result = ""; |
| 105 | f4(); |
| 106 | VERIFY(result == "DefCopyMoveDtorDtorDtor"); |
| 107 | result = ""; |
| 108 | f5(); |
| 109 | VERIFY(result == "DefMoveMoveDtorDtorDtor"); |
| 110 | result = ""; |
| 111 | f6(); |
| 112 | VERIFY(result == "DefMoveDtorMoveDtorDtor"); |
| 113 | result = ""; |
| 114 | } |