From 78a869ec7471a7c86d992a4cd3a506f5538995fc Mon Sep 17 00:00:00 2001 From: Takaya Saito Date: Tue, 12 Apr 2011 10:31:33 +0000 Subject: [PATCH] re PR libstdc++/48476 ([C++0x] conversion between std::tuple which have reference member is rejected) 2011-04-12 Takaya Saito 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. From-SVN: r172309 --- libstdc++-v3/ChangeLog | 10 +++ libstdc++-v3/include/std/tuple | 23 ++--- libstdc++-v3/testsuite/20_util/tuple/48476.cc | 51 +++++++++++ .../testsuite/20_util/tuple/cons/48476.cc | 27 ++++++ .../20_util/tuple/creation_functions/48476.cc | 85 +++++++++++++++++++ 5 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/tuple/48476.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c61a66ca03e..48b27d64657 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2011-04-12 Takaya Saito + + 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. + 2011-04-12 Allan McRae PR libstdc++/48566 diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 69513283f93..fb452aeb43e 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1,6 +1,6 @@ // -*- 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 - _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in) + template + _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 + template _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 @@ -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 @@ -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 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 00000000000..efe0007a629 --- /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 +// . + +#include +#include +#include +#include + +template + typename std::decay::type copy(T&& x) + { return std::forward(x); } + +// libstdc++/48476 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr p(new int()), q, r; + + std::tuple&, 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&, 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 00000000000..b5e3604d2ef --- /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 +// . + +#include + +void f() +{ + int i = 0; + std::tuple 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 00000000000..1607e455212 --- /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 +// . + +#include +#include +#include + +template + typename std::decay::type copy(T&& x) + { return std::forward(x); } + +template + void + check_tuple_cat(std::tuple t1, std::tuple t2) + { + bool test __attribute__((unused)) = true; + + typedef std::tuple 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::value, "" ); + static_assert( std::is_same::value, "" ); + static_assert( std::is_same::value, "" ); + static_assert( std::is_same::value, "" ); + + VERIFY( cat1 == cat2 ); + VERIFY( cat1 == cat3 ); + VERIFY( cat1 == cat4 ); + } + +// libstdc++/48476 +void test01() +{ + int i = 0; + std::tuple<> t0; + std::tuple t1(i); + std::tuple t2(i, 0); + std::tuple 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; +} -- 2.30.2