]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/tuple/cons/nested_tuple_construct.cc
re PR fortran/67496 (trans-array.c sanitizer runtime error: load of value 124, which...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / tuple / cons / nested_tuple_construct.cc
CommitLineData
818ab71a 1// Copyright (C) 2015-2016 Free Software Foundation, Inc.
057ce497
VV
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
5e2f2cd5
VV
18#include <string>
19#include <tuple>
20#include <testsuite_hooks.h>
21
22static std::string result;
23
24struct X {
25 int state; // this has to be here
26 X() {
27 result += "Def";
28 }
29
30 X(X const&) {
31 result += "Copy";
32 }
33
34 X(X&&) {
35 result += "Move";
36 }
37
38 ~X() {
39 result += "Dtor";
40 }
41};
42
43void f()
44{
45 X v;
46 std::tuple<X> t1{v};
47 std::tuple<std::tuple<X>&&> t2{std::move(t1)};
48 std::tuple<std::tuple<X>> t3{std::move(t2)};
49}
50
51void f2()
52{
53 X v;
54 std::tuple<X> t1{std::move(v)};
55 std::tuple<std::tuple<X>&&> t2{std::move(t1)};
56 std::tuple<std::tuple<X>> t3{std::move(t2)};
57}
58
59void f3()
60{
61 std::tuple<X> t1{X{}};
62 std::tuple<std::tuple<X>&&> t2{std::move(t1)};
63 std::tuple<std::tuple<X>> t3{std::move(t2)};
64}
65
7a667453
VV
66void f4()
67{
68 std::allocator<X> a;
69 X v;
70 std::tuple<X> t1{std::allocator_arg, a, v};
71 std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)};
72 std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)};
73}
74
75void f5()
76{
77 std::allocator<X> a;
78 X v;
79 std::tuple<X> t1{std::allocator_arg, a, std::move(v)};
80 std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)};
81 std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)};
82}
83
84void f6()
85{
86 std::allocator<X> a;
87 std::tuple<X> t1{std::allocator_arg, a, X{}};
88 std::tuple<std::tuple<X>&&> t2{std::allocator_arg, a, std::move(t1)};
89 std::tuple<std::tuple<X>> t3{std::allocator_arg, a, std::move(t2)};
90}
91
5e2f2cd5
VV
92int main()
93{
94 f();
95 VERIFY(result == "DefCopyMoveDtorDtorDtor");
96 result = "";
97 f2();
98 VERIFY(result == "DefMoveMoveDtorDtorDtor");
99 result = "";
100 f3();
101 VERIFY(result == "DefMoveDtorMoveDtorDtor");
102 result = "";
7a667453
VV
103 f4();
104 VERIFY(result == "DefCopyMoveDtorDtorDtor");
105 result = "";
106 f5();
107 VERIFY(result == "DefMoveMoveDtorDtorDtor");
108 result = "";
109 f6();
110 VERIFY(result == "DefMoveDtorMoveDtorDtor");
111 result = "";
5e2f2cd5 112}