]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
412386b2d866df4ba11c23cd2679be4891953273
[thirdparty/openembedded/openembedded-core-contrib.git] /
1 From 95c034f0075055720f37e340fd008d8d7cb45b4e Mon Sep 17 00:00:00 2001
2 From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
3 Date: Fri, 15 Apr 2011 14:52:57 +0000
4 Subject: [PATCH 125/200] 2011-04-15 Takaya Saito <gintensubaru@gmail.com>
5
6 PR libstdc++/48476
7 * include/std/tuple (_Tuple_impl<>::_Tuple_impl(_Tuple_impl<>&&),
8 _Tuple_impl<>::operator=(_Tuple_impl&&), _Tuple_impl<>::operator=
9 (_Tuple_impl<>&&), tuple_cat): Use std::forward where appropriate.
10 * testsuite/20_util/tuple/cons/48476.cc: New.
11 * testsuite/20_util/tuple/48476.cc: Likewise.
12 * testsuite/20_util/tuple/creation_functions/48476.cc: Likewise.
13
14
15 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172498 138bc75d-0d04-0410-961f-82ee72b054a4
16
17 index 6951328..fb452ae 100644
18 --- a/libstdc++-v3/include/std/tuple
19 +++ b/libstdc++-v3/include/std/tuple
20 @@ -1,6 +1,6 @@
21 // <tuple> -*- C++ -*-
22
23 -// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
24 +// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
25 //
26 // This file is part of the GNU ISO C++ Library. This library is free
27 // software; you can redistribute it and/or modify it under the
28 @@ -177,10 +177,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
29 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
30 : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
31
32 - template<typename... _UElements>
33 - _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
34 + template<typename _UHead, typename... _UTails>
35 + _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
36 : _Inherited(std::move(__in._M_tail())),
37 - _Base(std::move(__in._M_head())) { }
38 + _Base(std::forward<_UHead>(__in._M_head())) { }
39
40 _Tuple_impl&
41 operator=(const _Tuple_impl& __in)
42 @@ -193,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 _Tuple_impl&
44 operator=(_Tuple_impl&& __in)
45 {
46 - _M_head() = std::move(__in._M_head());
47 + _M_head() = std::forward<_Head>(__in._M_head());
48 _M_tail() = std::move(__in._M_tail());
49 return *this;
50 }
51 @@ -207,11 +207,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 return *this;
53 }
54
55 - template<typename... _UElements>
56 + template<typename _UHead, typename... _UTails>
57 _Tuple_impl&
58 - operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
59 + operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
60 {
61 - _M_head() = std::move(__in._M_head());
62 + _M_head() = std::forward<_UHead>(__in._M_head());
63 _M_tail() = std::move(__in._M_tail());
64 return *this;
65 }
66 @@ -672,7 +672,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
67 const tuple<_UElements...>& __u,
68 const __index_holder<_UIdx...>&)
69 { return tuple<_TElements..., _UElements...>
70 - (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
71 + (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
72
73 template<typename... _TElements, std::size_t... _TIdx,
74 typename... _UElements, std::size_t... _UIdx>
75 @@ -682,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 tuple<_UElements...>&& __u,
77 const __index_holder<_UIdx...>&)
78 { return tuple<_TElements..., _UElements...>
79 - (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
80 + (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
81
82 template<typename... _TElements, std::size_t... _TIdx,
83 typename... _UElements, std::size_t... _UIdx>
84 @@ -692,7 +692,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
85 tuple<_UElements...>&& __u,
86 const __index_holder<_UIdx...>&)
87 { return tuple<_TElements..., _UElements...>
88 - (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
89 + (std::forward<_TElements>(get<_TIdx>(__t))...,
90 + std::forward<_UElements>(get<_UIdx>(__u))...); }
91
92 template<typename... _TElements, typename... _UElements>
93 inline tuple<_TElements..., _UElements...>
94 diff --git a/libstdc++-v3/testsuite/20_util/tuple/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
95 new file mode 100644
96 index 0000000..efe0007
97 --- /dev/null
98 +++ b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
99 @@ -0,0 +1,51 @@
100 +// { dg-options "-std=gnu++0x" }
101 +
102 +// Copyright (C) 2011 Free Software Foundation, Inc.
103 +//
104 +// This file is part of the GNU ISO C++ Library. This library is free
105 +// software; you can redistribute it and/or modify it under the
106 +// terms of the GNU General Public License as published by the
107 +// Free Software Foundation; either version 3, or (at your option)
108 +// any later version.
109 +
110 +// This library is distributed in the hope that it will be useful,
111 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
112 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 +// GNU General Public License for more details.
114 +
115 +// You should have received a copy of the GNU General Public License along
116 +// with this library; see the file COPYING3. If not see
117 +// <http://www.gnu.org/licenses/>.
118 +
119 +#include <tuple>
120 +#include <type_traits>
121 +#include <memory>
122 +#include <testsuite_hooks.h>
123 +
124 +template<typename T>
125 + typename std::decay<T>::type copy(T&& x)
126 + { return std::forward<T>(x); }
127 +
128 +// libstdc++/48476
129 +void test01()
130 +{
131 + bool test __attribute__((unused)) = true;
132 +
133 + std::shared_ptr<int> p(new int()), q, r;
134 +
135 + std::tuple<std::shared_ptr<int>&, int> t0(p, 23), t1(q, 0);
136 + t1 = copy(t0); // shall be equivalent to
137 + // q = p; std::get<1>(t1) = std::get<1>(t0);
138 + VERIFY( q == p );
139 +
140 + std::tuple<std::shared_ptr<int>&, char> t2(r, 0);
141 + t2 = copy(t1); // shall be equivalent to
142 + // r = q; std::get<1>(t2) = std::get<1>(t1);
143 + VERIFY( r == q );
144 +}
145 +
146 +int main()
147 +{
148 + test01();
149 + return 0;
150 +}
151 diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
152 new file mode 100644
153 index 0000000..b5e3604
154 --- /dev/null
155 +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
156 @@ -0,0 +1,27 @@
157 +// { dg-options "-std=gnu++0x" }
158 +// { dg-do compile }
159 +
160 +// Copyright (C) 2011 Free Software Foundation, Inc.
161 +//
162 +// This file is part of the GNU ISO C++ Library. This library is free
163 +// software; you can redistribute it and/or modify it under the
164 +// terms of the GNU General Public License as published by the
165 +// Free Software Foundation; either version 3, or (at your option)
166 +// any later version.
167 +
168 +// This library is distributed in the hope that it will be useful,
169 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
170 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
171 +// GNU General Public License for more details.
172 +
173 +// You should have received a copy of the GNU General Public License along
174 +// with this library; see the file COPYING3. If not see
175 +// <http://www.gnu.org/licenses/>.
176 +
177 +#include <tuple>
178 +
179 +void f()
180 +{
181 + int i = 0;
182 + std::tuple<int&, int> t __attribute__((unused)) = std::forward_as_tuple(i, 0);
183 +}
184 diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
185 new file mode 100644
186 index 0000000..1607e45
187 --- /dev/null
188 +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
189 @@ -0,0 +1,85 @@
190 +// { dg-options "-std=gnu++0x" }
191 +
192 +// Copyright (C) 2011 Free Software Foundation, Inc.
193 +//
194 +// This file is part of the GNU ISO C++ Library. This library is free
195 +// software; you can redistribute it and/or modify it under the
196 +// terms of the GNU General Public License as published by the
197 +// Free Software Foundation; either version 3, or (at your option)
198 +// any later version.
199 +
200 +// This library is distributed in the hope that it will be useful,
201 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
202 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 +// GNU General Public License for more details.
204 +
205 +// You should have received a copy of the GNU General Public License along
206 +// with this library; see the file COPYING3. If not see
207 +// <http://www.gnu.org/licenses/>.
208 +
209 +#include <tuple>
210 +#include <type_traits>
211 +#include <testsuite_hooks.h>
212 +
213 +template<typename T>
214 + typename std::decay<T>::type copy(T&& x)
215 + { return std::forward<T>(x); }
216 +
217 +template<typename... Args1, typename... Args2>
218 + void
219 + check_tuple_cat(std::tuple<Args1...> t1, std::tuple<Args2...> t2)
220 + {
221 + bool test __attribute__((unused)) = true;
222 +
223 + typedef std::tuple<Args1..., Args2...> concatenated;
224 +
225 + auto cat1 = std::tuple_cat( t1, t2 );
226 + auto cat2 = std::tuple_cat(copy(t1), t2 );
227 + auto cat3 = std::tuple_cat( t1, copy(t2));
228 + auto cat4 = std::tuple_cat(copy(t1), copy(t2));
229 +
230 + static_assert( std::is_same<decltype(cat1), concatenated>::value, "" );
231 + static_assert( std::is_same<decltype(cat2), concatenated>::value, "" );
232 + static_assert( std::is_same<decltype(cat3), concatenated>::value, "" );
233 + static_assert( std::is_same<decltype(cat4), concatenated>::value, "" );
234 +
235 + VERIFY( cat1 == cat2 );
236 + VERIFY( cat1 == cat3 );
237 + VERIFY( cat1 == cat4 );
238 + }
239 +
240 +// libstdc++/48476
241 +void test01()
242 +{
243 + int i = 0;
244 + std::tuple<> t0;
245 + std::tuple<int&> t1(i);
246 + std::tuple<int&, int> t2(i, 0);
247 + std::tuple<int const&, int, double> t3(i, 0, 0);
248 +
249 + check_tuple_cat(t0, t0);
250 + check_tuple_cat(t0, t1);
251 + check_tuple_cat(t0, t2);
252 + check_tuple_cat(t0, t3);
253 +
254 + check_tuple_cat(t1, t0);
255 + check_tuple_cat(t1, t1);
256 + check_tuple_cat(t1, t2);
257 + check_tuple_cat(t1, t3);
258 +
259 + check_tuple_cat(t2, t0);
260 + check_tuple_cat(t2, t1);
261 + check_tuple_cat(t2, t2);
262 + check_tuple_cat(t2, t3);
263 +
264 + check_tuple_cat(t3, t0);
265 + check_tuple_cat(t3, t1);
266 + check_tuple_cat(t3, t2);
267 + check_tuple_cat(t3, t3);
268 +}
269 +
270 +int main()
271 +{
272 + test01();
273 + return 0;
274 +}
275 --
276 1.7.0.4
277