From patchwork Tue Apr 12 10:32:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 90764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9B42EB6F10 for ; Tue, 12 Apr 2011 20:33:16 +1000 (EST) Received: (qmail 4540 invoked by alias); 12 Apr 2011 10:33:10 -0000 Received: (qmail 4522 invoked by uid 22791); 12 Apr 2011 10:33:08 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp209.alice.it (HELO smtp209.alice.it) (82.57.200.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Apr 2011 10:32:59 +0000 Received: from [192.168.1.4] (79.33.220.194) by smtp209.alice.it (8.5.124.08) id 4D498EF305E28B23; Tue, 12 Apr 2011 12:32:57 +0200 Message-ID: <4DA42A57.8010203@oracle.com> Date: Tue, 12 Apr 2011 12:32:55 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Fix libstdc++/48476 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, barring issues over the next days, will go in 4_6-branch too. Tested x86_64-linux, committed to mainline. Paolo. //////////////////////// 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. Index: include/std/tuple =================================================================== --- include/std/tuple (revision 172305) +++ include/std/tuple (working copy) @@ -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 @@ _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 @@ _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 @@ 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 @@ 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 @@ 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 @@ 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...> Index: testsuite/20_util/tuple/48476.cc =================================================================== --- testsuite/20_util/tuple/48476.cc (revision 0) +++ testsuite/20_util/tuple/48476.cc (revision 0) @@ -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; +} Index: testsuite/20_util/tuple/cons/48476.cc =================================================================== --- testsuite/20_util/tuple/cons/48476.cc (revision 0) +++ testsuite/20_util/tuple/cons/48476.cc (revision 0) @@ -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); +} Index: testsuite/20_util/tuple/creation_functions/48476.cc =================================================================== --- testsuite/20_util/tuple/creation_functions/48476.cc (revision 0) +++ testsuite/20_util/tuple/creation_functions/48476.cc (revision 0) @@ -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; +}