]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add noexcept to std::function swap
authorJonathan Wakely <jwakely@redhat.com>
Mon, 17 Oct 2016 17:03:31 +0000 (18:03 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 17 Oct 2016 17:03:31 +0000 (18:03 +0100)
Backport from mainline:
2016-08-22  Jonathan Wakely  <jwakely@redhat.com>

PR libstdc++/77322
* doc/xml/manual/intro.xml: Document DR 2062 change.
* include/std/functional (function::swap): Add noexcept.
(swap(function<Res(Args...)&, function<Res(Args...)&)): Likewise.
* testsuite/20_util/function/77322.cc: New test.

From-SVN: r241266

libstdc++-v3/ChangeLog
libstdc++-v3/doc/xml/manual/intro.xml
libstdc++-v3/include/std/functional
libstdc++-v3/testsuite/20_util/function/77322.cc [new file with mode: 0644]

index effb95d0f8897d1e305fecdb4d8c8c5e3474b256..d15e381eebbda0cfefaceecad20b51c2148a1247 100644 (file)
@@ -1,3 +1,14 @@
+2016-10-17  Jonathan Wakely  <jwakely@redhat.com>
+
+       Backport from mainline:
+       2016-08-22  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/77322
+       * doc/xml/manual/intro.xml: Document DR 2062 change.
+       * include/std/functional (function::swap): Add noexcept.
+       (swap(function<Res(Args...)&, function<Res(Args...)&)): Likewise.
+       * testsuite/20_util/function/77322.cc: New test.
+
 2016-10-17  Jonathan Wakely  <jwakely@redhat.com>
 
        Backport from mainline:
index 1deb4136bcfb8b26d6c7a5118e6261764cf5f052..8c951dc5a14b17ad69041a3d758116b90bc924df 100644 (file)
@@ -840,6 +840,12 @@ requirements of the license of GCC.
     <listitem><para>Add additional overloads.
     </para></listitem></varlistentry>
 
+    <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2062">2062</link>:
+       <emphasis>2062. Effect contradictions w/o no-throw guarantee of <code>std::function</code> swaps</emphasis>
+    </term>
+    <listitem><para>Add <code>noexcept</code> to swap functions.
+    </para></listitem></varlistentry>
+
     <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2063">2063</link>:
        <emphasis>Contradictory requirements for string move assignment</emphasis>
     </term>
index e3fce0cada931e64731433c3be23238ada577b7f..a8d81d27577fe5a79222c4ca8f5bf9445bd5e252 100644 (file)
@@ -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<typename _Res, typename... _Args>
     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 (file)
index 0000000..52abdf6
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <functional>
+
+// PR libstdc++/77322
+std::function<void()> f, g;
+static_assert( noexcept(f.swap(g)), "member swap is noexcept" );
+static_assert( noexcept(swap(f, g)), "non-member swap is noexcept" );