summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0125-2011-04-15-Takaya-Saito-gintensubaru-gmail.com.patch
blob: ecf212707b0583622d40af56be971b1130e206a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
Upstream-Status: Inappropriate [Backport]
From 95c034f0075055720f37e340fd008d8d7cb45b4e Mon Sep 17 00:00:00 2001
From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 15 Apr 2011 14:52:57 +0000
Subject: [PATCH 125/200] 2011-04-15  Takaya Saito  <gintensubaru@gmail.com>

	PR libstdc++/48476
	* include/std/tuple (_Tuple_impl<>::_Tuple_impl(_Tuple_impl<>&&),
	_Tuple_impl<>::operator=(_Tuple_impl&&), _Tuple_impl<>::operator=
	(_Tuple_impl<>&&), tuple_cat): Use std::forward where appropriate.
	* testsuite/20_util/tuple/cons/48476.cc: New.
	* testsuite/20_util/tuple/48476.cc: Likewise.
	* testsuite/20_util/tuple/creation_functions/48476.cc: Likewise.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172498 138bc75d-0d04-0410-961f-82ee72b054a4

index 6951328..fb452ae 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -1,6 +1,6 @@
 // <tuple> -*- C++ -*-
 
-// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -177,10 +177,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
 	: _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
 
-      template<typename... _UElements>
-        _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
+      template<typename _UHead, typename... _UTails>
+        _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
 	: _Inherited(std::move(__in._M_tail())),
-	  _Base(std::move(__in._M_head())) { }
+	  _Base(std::forward<_UHead>(__in._M_head())) { }
 
       _Tuple_impl&
       operator=(const _Tuple_impl& __in)
@@ -193,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _Tuple_impl&
       operator=(_Tuple_impl&& __in)
       {
-	_M_head() = std::move(__in._M_head());
+	_M_head() = std::forward<_Head>(__in._M_head());
 	_M_tail() = std::move(__in._M_tail());
 	return *this;
       }
@@ -207,11 +207,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  return *this;
 	}
 
-      template<typename... _UElements>
+      template<typename _UHead, typename... _UTails>
         _Tuple_impl&
-        operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
+        operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
         {
-	  _M_head() = std::move(__in._M_head());
+	  _M_head() = std::forward<_UHead>(__in._M_head());
 	  _M_tail() = std::move(__in._M_tail());
 	  return *this;
 	}
@@ -672,7 +672,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		       const tuple<_UElements...>& __u,
 		       const __index_holder<_UIdx...>&)
     { return tuple<_TElements..., _UElements...>
-	(std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
+	(std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
 
   template<typename... _TElements, std::size_t... _TIdx,
 	   typename... _UElements, std::size_t... _UIdx>
@@ -682,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		       tuple<_UElements...>&& __u,
 		       const __index_holder<_UIdx...>&)
     { return tuple<_TElements..., _UElements...>
-	(get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
+	(get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
 
   template<typename... _TElements, std::size_t... _TIdx,
 	   typename... _UElements, std::size_t... _UIdx> 
@@ -692,7 +692,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		       tuple<_UElements...>&& __u,
 		       const __index_holder<_UIdx...>&)
     { return tuple<_TElements..., _UElements...>
-	(std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
+	(std::forward<_TElements>(get<_TIdx>(__t))...,
+	 std::forward<_UElements>(get<_UIdx>(__u))...); }
 
   template<typename... _TElements, typename... _UElements>
     inline tuple<_TElements..., _UElements...> 
diff --git a/libstdc++-v3/testsuite/20_util/tuple/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
new file mode 100644
index 0000000..efe0007
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tuple>
+#include <type_traits>
+#include <memory>
+#include <testsuite_hooks.h>
+
+template<typename T>
+  typename std::decay<T>::type copy(T&& x)
+  { return std::forward<T>(x); }
+
+// libstdc++/48476
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::shared_ptr<int> p(new int()), q, r;
+  
+  std::tuple<std::shared_ptr<int>&, int>  t0(p, 23), t1(q, 0);
+  t1 = copy(t0);  // shall be equivalent to
+                  // q = p; std::get<1>(t1) = std::get<1>(t0);
+  VERIFY( q == p ); 
+
+  std::tuple<std::shared_ptr<int>&, char> t2(r, 0);
+  t2 = copy(t1);  // shall be equivalent to
+                  // r = q; std::get<1>(t2) = std::get<1>(t1);
+  VERIFY( r == q );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
new file mode 100644
index 0000000..b5e3604
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
@@ -0,0 +1,27 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tuple>
+
+void f()
+{
+  int i = 0;
+  std::tuple<int&, int> t __attribute__((unused)) = std::forward_as_tuple(i, 0);
+}
diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
new file mode 100644
index 0000000..1607e45
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
@@ -0,0 +1,85 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tuple>
+#include <type_traits>
+#include <testsuite_hooks.h>
+
+template<typename T>
+  typename std::decay<T>::type copy(T&& x)
+  { return std::forward<T>(x); }
+
+template<typename... Args1, typename... Args2>
+  void
+  check_tuple_cat(std::tuple<Args1...> t1, std::tuple<Args2...> t2)
+  {
+    bool test __attribute__((unused)) = true;
+
+    typedef std::tuple<Args1..., Args2...> concatenated;
+  
+    auto cat1 = std::tuple_cat(     t1,       t2 );
+    auto cat2 = std::tuple_cat(copy(t1),      t2 );
+    auto cat3 = std::tuple_cat(     t1,  copy(t2));
+    auto cat4 = std::tuple_cat(copy(t1), copy(t2));
+  
+    static_assert( std::is_same<decltype(cat1), concatenated>::value, "" );
+    static_assert( std::is_same<decltype(cat2), concatenated>::value, "" );
+    static_assert( std::is_same<decltype(cat3), concatenated>::value, "" );
+    static_assert( std::is_same<decltype(cat4), concatenated>::value, "" );
+  
+    VERIFY( cat1 == cat2 );
+    VERIFY( cat1 == cat3 );
+    VERIFY( cat1 == cat4 );
+  }
+
+// libstdc++/48476
+void test01()
+{
+  int i = 0;
+  std::tuple<> t0;
+  std::tuple<int&> t1(i);
+  std::tuple<int&, int> t2(i, 0);
+  std::tuple<int const&, int, double> t3(i, 0, 0);
+  
+  check_tuple_cat(t0, t0);
+  check_tuple_cat(t0, t1);
+  check_tuple_cat(t0, t2);
+  check_tuple_cat(t0, t3);
+  
+  check_tuple_cat(t1, t0);
+  check_tuple_cat(t1, t1);
+  check_tuple_cat(t1, t2);
+  check_tuple_cat(t1, t3);
+  
+  check_tuple_cat(t2, t0);
+  check_tuple_cat(t2, t1);
+  check_tuple_cat(t2, t2);
+  check_tuple_cat(t2, t3);
+  
+  check_tuple_cat(t3, t0);
+  check_tuple_cat(t3, t1);
+  check_tuple_cat(t3, t2);
+  check_tuple_cat(t3, t3);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
-- 
1.7.0.4

OpenPOWER on IntegriCloud