I'm amazed nobody's noticed this before, but std::function's move
constructor and move assignment operator are not noexcept. Fixed like
so.

        PR libstdc++/81017
        * include/bits/std_function.h (function::function(function&&))
        (function::operator=(funtion&&)): Add noexcept.
        * testsuite/20_util/function/assign/move.cc: Check for noexcept.
        * testsuite/20_util/function/cons/move.cc: Likewise.

Tested powerpc64le-linux, committed to trunk.

I think this should be backported too.

commit 9f20b90ff85d9581a3f82dcfd9300775316b6fd3
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Jun 8 15:15:26 2017 +0100

    PR libstdc++/81017 add noexcept to std::function move operations
    
        PR libstdc++/81017
        * include/bits/std_function.h (function::function(function&&))
        (function::operator=(funtion&&)): Add noexcept.
        * testsuite/20_util/function/assign/move.cc: Check for noexcept.
        * testsuite/20_util/function/cons/move.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/std_function.h 
b/libstdc++-v3/include/bits/std_function.h
index c4ea347..a9ba756 100644
--- a/libstdc++-v3/include/bits/std_function.h
+++ b/libstdc++-v3/include/bits/std_function.h
@@ -438,7 +438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  The newly-created %function contains the target of @a __x
        *  (if it has one).
        */
-      function(function&& __x) : _Function_base()
+      function(function&& __x) noexcept : _Function_base()
       {
        __x.swap(*this);
       }
@@ -495,7 +495,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  object, then this operation will not throw an %exception.
        */
       function&
-      operator=(function&& __x)
+      operator=(function&& __x) noexcept
       {
        function(std::move(__x)).swap(*this);
        return *this;
diff --git a/libstdc++-v3/testsuite/20_util/function/assign/move.cc 
b/libstdc++-v3/testsuite/20_util/function/assign/move.cc
index 5264623..8658527 100644
--- a/libstdc++-v3/testsuite/20_util/function/assign/move.cc
+++ b/libstdc++-v3/testsuite/20_util/function/assign/move.cc
@@ -38,11 +38,12 @@ void test01()
   fo2 = (std::move(fo));
   VERIFY( static_cast<bool>(fo2) );
   VERIFY( fo2() == 2 );
+
+  static_assert(std::is_nothrow_move_assignable<function>::value,
+               "PR libstdc++/81017");
 }
 
 int main()
 {
   test01();
-
-  return 0;
 }
diff --git a/libstdc++-v3/testsuite/20_util/function/cons/move.cc 
b/libstdc++-v3/testsuite/20_util/function/cons/move.cc
index 1cdfeed..7dbc511 100644
--- a/libstdc++-v3/testsuite/20_util/function/cons/move.cc
+++ b/libstdc++-v3/testsuite/20_util/function/cons/move.cc
@@ -36,11 +36,12 @@ void test01()
   function fo2(std::move(fo));
   VERIFY( static_cast<bool>(fo2) );
   VERIFY( fo2() == 2 );
+
+  static_assert(std::is_nothrow_move_constructible<function>::value,
+               "PR libstdc++/81017");
 }
 
 int main()
 {
   test01();
-
-  return 0;
 }

Reply via email to