From: Jonathan Wakely Date: Mon, 17 Oct 2016 17:03:31 +0000 (+0100) Subject: Add noexcept to std::function swap X-Git-Tag: releases/gcc-5.5.0~761 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ddedda20090d314f7fce3f89d7461feda85a705;p=thirdparty%2Fgcc.git Add noexcept to std::function swap Backport from mainline: 2016-08-22 Jonathan Wakely PR libstdc++/77322 * doc/xml/manual/intro.xml: Document DR 2062 change. * include/std/functional (function::swap): Add noexcept. (swap(function + + Backport from mainline: + 2016-08-22 Jonathan Wakely + + PR libstdc++/77322 + * doc/xml/manual/intro.xml: Document DR 2062 change. + * include/std/functional (function::swap): Add noexcept. + (swap(function Backport from mainline: diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 1deb4136bcfb..8c951dc5a14b 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -840,6 +840,12 @@ requirements of the license of GCC. Add additional overloads. + 2062: + 2062. Effect contradictions w/o no-throw guarantee of std::function swaps + + Add noexcept to swap functions. + + 2063: Contradictory requirements for string move assignment diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index e3fce0cada93..a8d81d27577f 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -2151,7 +2151,7 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type) * Swap the targets of @c this function object and @a __f. This * function will not throw an %exception. */ - void swap(function& __x) + void swap(function& __x) noexcept { std::swap(_M_functor, __x._M_functor); std::swap(_M_manager, __x._M_manager); @@ -2364,9 +2364,11 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type) * * This function will not throw an %exception. */ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2062. Effect contradictions w/o no-throw guarantee of std::function swaps template inline void - swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) + swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept { __x.swap(__y); } _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/20_util/function/77322.cc b/libstdc++-v3/testsuite/20_util/function/77322.cc new file mode 100644 index 000000000000..52abdf6b2055 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/77322.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2016 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 +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +#include + +// PR libstdc++/77322 +std::function f, g; +static_assert( noexcept(f.swap(g)), "member swap is noexcept" ); +static_assert( noexcept(swap(f, g)), "non-member swap is noexcept" );