From patchwork Tue Jun 21 23:04:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 101382 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 2AB08B6F8E for ; Wed, 22 Jun 2011 09:03:42 +1000 (EST) Received: (qmail 26441 invoked by alias); 21 Jun 2011 23:03:37 -0000 Received: (qmail 26421 invoked by uid 22791); 21 Jun 2011 23:03:36 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_BL_SPAMCOP_NET, 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, 21 Jun 2011 23:03:22 +0000 Received: from [192.168.1.4] (79.52.233.79) by smtp209.alice.it (8.5.124.08) id 4DE658F801F07323; Wed, 22 Jun 2011 01:03:20 +0200 Message-ID: <4E012363.8000300@oracle.com> Date: Wed, 22 Jun 2011 01:04:03 +0200 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] Use noexcept in array swap 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, tested x86_64-linux, committed. Paolo. /////////////////////// 2011-06-22 Daniel Krugler Paolo Carlini * include/bits/move.h (__is_nothrow_swappable): Add. (swap(_Tp(&)[_Nm], _Tp(&)[_Nm])): Use noexcept. * include/bits/algorithmfwd.h: Adjust. * testsuite/25_algorithms/swap/noexcept.cc: New. Index: include/bits/move.h =================================================================== --- include/bits/move.h (revision 175263) +++ include/bits/move.h (working copy) @@ -152,12 +152,22 @@ __b = _GLIBCXX_MOVE(__tmp); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // To work around c++/49045. + template + struct __is_nothrow_swappable + { static const bool value = noexcept(swap(std::declval<_Tp&>(), + std::declval<_Tp&>())); }; +#endif + // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 809. std::swap should be overloaded for array types. template inline void swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) - // noexcept waits for c++/49045 +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + noexcept(__is_nothrow_swappable<_Tp>::value) +#endif { for (size_t __n = 0; __n < _Nm; ++__n) swap(__a[__n], __b[__n]); Index: include/bits/algorithmfwd.h =================================================================== --- include/bits/algorithmfwd.h (revision 175263) +++ include/bits/algorithmfwd.h (working copy) @@ -558,7 +558,11 @@ template void - swap(_Tp (&)[_Nm], _Tp (&)[_Nm]); + swap(_Tp (&)[_Nm], _Tp (&)[_Nm]) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + noexcept(__is_nothrow_swappable<_Tp>::value) +#endif + ; template _FIter2 Index: testsuite/25_algorithms/swap/noexcept.cc =================================================================== --- testsuite/25_algorithms/swap/noexcept.cc (revision 0) +++ testsuite/25_algorithms/swap/noexcept.cc (revision 0) @@ -0,0 +1,26 @@ +// { dg-do compile } +// { 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 + +static_assert(noexcept(std::swap(std::declval(), + std::declval())), "Error"); +static_assert(noexcept(std::swap(std::declval(), + std::declval())), "Error");