* [PATCH] PR libstdc++/81017 add noexcept to std::function move operations
@ 2017-06-08 14:29 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2017-06-08 14:29 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 482 bytes --]
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.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2391 bytes --]
commit 9f20b90ff85d9581a3f82dcfd9300775316b6fd3
Author: Jonathan Wakely <jwakely@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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-06-08 14:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-08 14:29 [PATCH] PR libstdc++/81017 add noexcept to std::function move operations Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).