From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30942 invoked by alias); 18 May 2011 00:15:30 -0000 Received: (qmail 30888 invoked by uid 22791); 18 May 2011 00:15:25 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SARE_OBFU_PART_ION X-Spam-Check-By: sourceware.org Received: from smtp204.alice.it (HELO smtp204.alice.it) (82.57.200.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 May 2011 00:15:07 +0000 Received: from [192.168.1.4] (79.51.12.178) by smtp204.alice.it (8.5.124.08) id 4D7E0F6405A3614C; Wed, 18 May 2011 02:15:04 +0200 Message-ID: <4DD30F57.5020803@oracle.com> Date: Wed, 18 May 2011 06:52:00 -0000 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] vs noexcept Content-Type: multipart/mixed; boundary="------------050302020404020305060403" X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01248.txt.bz2 This is a multi-part message in MIME format. --------------050302020404020305060403 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 130 Hi, this time too, took the occasion to add the get(tuple&&) bits. Tested x86_64-linux, committed. Paolo. /////////////////// --------------050302020404020305060403 Content-Type: text/plain; name="CL_noexcept_tuple" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="CL_noexcept_tuple" Content-length: 357 2011-05-17 Paolo Carlini * include/std/tuple: Use noexcept where appropriate. (tuple<>::swap): Rework implementation. (_Head_base<>::_M_swap_impl): Remove. (get(std::tuple<>&&)): Add. * testsuite/20_util/tuple/element_access/get2.cc: New. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line number. --------------050302020404020305060403 Content-Type: text/plain; name="patch_noexcept_tuple" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch_noexcept_tuple" Content-length: 8756 Index: include/std/tuple =================================================================== --- include/std/tuple (revision 173832) +++ include/std/tuple (working copy) @@ -59,6 +59,15 @@ struct __add_ref<_Tp&> { typedef _Tp& type; }; + // Adds an rvalue reference to a non-reference type. + template + struct __add_r_ref + { typedef _Tp&& type; }; + + template + struct __add_r_ref<_Tp&> + { typedef _Tp& type; }; + template struct _Head_base; @@ -78,13 +87,6 @@ _Head& _M_head() { return *this; } const _Head& _M_head() const { return *this; } - - void - _M_swap_impl(_Head& __h) - { - using std::swap; - swap(__h, _M_head()); - } }; template @@ -103,13 +105,6 @@ _Head& _M_head() { return _M_head_impl; } const _Head& _M_head() const { return _M_head_impl; } - void - _M_swap_impl(_Head& __h) - { - using std::swap; - swap(__h, _M_head()); - } - _Head _M_head_impl; }; @@ -130,9 +125,11 @@ */ template struct _Tuple_impl<_Idx> - { + { + template friend class _Tuple_impl; + protected: - void _M_swap_impl(_Tuple_impl&) { /* no-op */ } + void _M_swap(_Tuple_impl&) noexcept { /* no-op */ } }; /** @@ -145,6 +142,8 @@ : public _Tuple_impl<_Idx + 1, _Tail...>, private _Head_base<_Idx, _Head, std::is_empty<_Head>::value> { + template friend class _Tuple_impl; + typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base; @@ -218,10 +217,14 @@ protected: void - _M_swap_impl(_Tuple_impl& __in) + _M_swap(_Tuple_impl& __in) + noexcept(noexcept(swap(std::declval<_Head&>(), + std::declval<_Head&>())) + && noexcept(__in._M_tail()._M_swap(__in._M_tail()))) { - _Base::_M_swap_impl(__in._M_head()); - _Inherited::_M_swap_impl(__in._M_tail()); + using std::swap; + swap(this->_M_head(), __in._M_head()); + _Inherited::_M_swap(__in._M_tail()); } }; @@ -300,14 +303,15 @@ void swap(tuple& __in) - { _Inherited::_M_swap_impl(__in); } + noexcept(noexcept(__in._M_swap(__in))) + { _Inherited::_M_swap(__in); } }; template<> class tuple<> { public: - void swap(tuple&) { /* no-op */ } + void swap(tuple&) noexcept { /* no-op */ } }; /// tuple (2-element), with construction and assignment from a pair. @@ -360,6 +364,7 @@ tuple& operator=(tuple&& __in) + // noexcept has to wait is_nothrow_move_assignable { static_cast<_Inherited&>(*this) = std::move(__in); return *this; @@ -392,7 +397,7 @@ template tuple& - operator=(pair<_U1, _U2>&& __in) + operator=(pair<_U1, _U2>&& __in) noexcept { this->_M_head() = std::forward<_U1>(__in.first); this->_M_tail()._M_head() = std::forward<_U2>(__in.second); @@ -401,11 +406,8 @@ void swap(tuple& __in) - { - using std::swap; - swap(this->_M_head(), __in._M_head()); - swap(this->_M_tail()._M_head(), __in._M_tail()._M_head()); - } + noexcept(noexcept(__in._M_swap(__in))) + { _Inherited::_M_swap(__in); } }; /// tuple (1-element). @@ -473,7 +475,8 @@ void swap(tuple& __in) - { _Inherited::_M_swap_impl(__in); } + noexcept(noexcept(__in._M_swap(__in))) + { _Inherited::_M_swap(__in); } }; @@ -522,22 +525,31 @@ __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) { return __t._M_head(); } - // Return a reference (const reference) to the ith element of a tuple. - // Any const or non-const ref elements are returned with their original type. + // Return a reference (const reference, rvalue reference) to the ith element + // of a tuple. Any const or non-const ref elements are returned with their + // original type. template inline typename __add_ref< - typename tuple_element<__i, tuple<_Elements...> >::type + typename tuple_element<__i, tuple<_Elements...>>::type >::type - get(tuple<_Elements...>& __t) + get(tuple<_Elements...>& __t) noexcept { return __get_helper<__i>(__t); } template inline typename __add_c_ref< - typename tuple_element<__i, tuple<_Elements...> >::type + typename tuple_element<__i, tuple<_Elements...>>::type >::type - get(const tuple<_Elements...>& __t) + get(const tuple<_Elements...>& __t) noexcept { return __get_helper<__i>(__t); } + template + inline typename __add_r_ref< + typename tuple_element<__i, tuple<_Elements...>>::type + >::type + get(tuple<_Elements...>&& __t) noexcept + { return std::forward>::type&&>(get<__i>(__t)); } + // This class helps construct the various comparison operations on tuples template @@ -628,7 +640,7 @@ template inline tuple<_Elements&&...> - forward_as_tuple(_Elements&&... __args) + forward_as_tuple(_Elements&&... __args) noexcept { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); } template struct __index_holder { }; @@ -737,12 +749,13 @@ template inline tuple<_Elements&...> - tie(_Elements&... __args) + tie(_Elements&... __args) noexcept { return tuple<_Elements&...>(__args...); } template inline void swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) + noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } // A class (and instance) which can be used in 'tie' when an element Index: testsuite/20_util/tuple/element_access/get2.cc =================================================================== --- testsuite/20_util/tuple/element_access/get2.cc (revision 0) +++ testsuite/20_util/tuple/element_access/get2.cc (revision 0) @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2011-05-17 Paolo Carlini +// +// 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 test01() +{ + std::tuple t1; + + int&& t1one __attribute__((unused)) = std::get<0>(std::move(t1)); + + std::tuple t2; + + float&& t2one __attribute__((unused)) = std::get<0>(std::move(t2)); + int&& t2two __attribute__((unused)) = std::get<1>(std::move(t2)); + + std::tuple t3; + + short&& t3one __attribute__((unused)) = std::get<0>(std::move(t3)); + int&& t3two __attribute__((unused)) = std::get<1>(std::move(t3)); + double&& t3thr __attribute__((unused)) = std::get<2>(std::move(t3)); +} Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 173832) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -51,7 +51,7 @@ // { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 469 } -// { dg-warning "note" "" { target *-*-* } 587 } +// { dg-warning "note" "" { target *-*-* } 599 } // { dg-warning "note" "" { target *-*-* } 1056 } // { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 342 } --------------050302020404020305060403--