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