Add tests to check that swap(std::function, std::function) is noexcept. This is LWG#2062, but we already do this. No changes to the library, just adding tests.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283780 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2016-10-10 16:47:48 +00:00
parent f7b867b342
commit e9115a1b41

View File

@@ -12,13 +12,14 @@
// class function<R(ArgTypes...)> // class function<R(ArgTypes...)>
// template <MoveConstructible R, MoveConstructible ... ArgTypes> // template <MoveConstructible R, MoveConstructible ... ArgTypes>
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); // void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
#include <functional> #include <functional>
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "test_macros.h"
#include "count_new.hpp" #include "count_new.hpp"
class A class A
@@ -63,6 +64,9 @@ int main()
{ {
std::function<int(int)> f1 = A(1); std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = A(2); std::function<int(int)> f2 = A(2);
#if TEST_STD_VER >= 11
static_assert(noexcept(swap(f1, f2)), "" );
#endif
assert(A::count == 2); assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2)); assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f1.target<A>()->id() == 1); assert(f1.target<A>()->id() == 1);
@@ -78,6 +82,9 @@ int main()
{ {
std::function<int(int)> f1 = A(1); std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = g; std::function<int(int)> f2 = g;
#if TEST_STD_VER >= 11
static_assert(noexcept(swap(f1, f2)), "" );
#endif
assert(A::count == 1); assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1)); assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1); assert(f1.target<A>()->id() == 1);
@@ -93,6 +100,9 @@ int main()
{ {
std::function<int(int)> f1 = g; std::function<int(int)> f1 = g;
std::function<int(int)> f2 = A(1); std::function<int(int)> f2 = A(1);
#if TEST_STD_VER >= 11
static_assert(noexcept(swap(f1, f2)), "" );
#endif
assert(A::count == 1); assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1)); assert(globalMemCounter.checkOutstandingNewEq(1));
assert(*f1.target<int(*)(int)>() == g); assert(*f1.target<int(*)(int)>() == g);
@@ -108,6 +118,9 @@ int main()
{ {
std::function<int(int)> f1 = g; std::function<int(int)> f1 = g;
std::function<int(int)> f2 = h; std::function<int(int)> f2 = h;
#if TEST_STD_VER >= 11
static_assert(noexcept(swap(f1, f2)), "" );
#endif
assert(A::count == 0); assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0)); assert(globalMemCounter.checkOutstandingNewEq(0));
assert(*f1.target<int(*)(int)>() == g); assert(*f1.target<int(*)(int)>() == g);