summaryrefslogtreecommitdiff
path: root/test/std/utilities/function.objects/func.wrap
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/utilities/function.objects/func.wrap')
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.fail.cpp25
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp29
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp15
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp21
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp21
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp25
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp3
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp29
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp24
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp30
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp1
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp27
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp3
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp60
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp3
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp119
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp4
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp175
18 files changed, 515 insertions, 99 deletions
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.fail.cpp
new file mode 100644
index 000000000000..e156fa966ac5
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.fail.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+// XFAIL: c++11, c++14
+
+// <functional>
+
+#include <functional>
+#include <type_traits>
+
+#include "test_macros.h"
+
+struct S : public std::function<void()> { using function::function; };
+
+int main() {
+ S f1( [](){} );
+ S f2(std::allocator_arg, std::allocator<int>{}, f1);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp
new file mode 100644
index 000000000000..5bdf9e98e897
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+// REQUIRES-ANY: c++11, c++14
+
+// <functional>
+
+// See https://llvm.org/bugs/show_bug.cgi?id=20002
+
+#include <functional>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using Fn = std::function<void()>;
+struct S : public std::function<void()> { using function::function; };
+
+int main() {
+ S s( [](){} );
+ S f1( s );
+ S f2(std::allocator_arg, std::allocator<int>{}, s);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
index 58192c928d58..1a9206e0e7f3 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
@@ -12,13 +12,14 @@
// class function<R(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 <cstdlib>
#include <cassert>
+#include "test_macros.h"
#include "count_new.hpp"
class A
@@ -63,6 +64,9 @@ int main()
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = A(2);
+#if TEST_STD_VER >= 11
+ static_assert(noexcept(swap(f1, f2)), "" );
+#endif
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f1.target<A>()->id() == 1);
@@ -78,6 +82,9 @@ int main()
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = g;
+#if TEST_STD_VER >= 11
+ static_assert(noexcept(swap(f1, f2)), "" );
+#endif
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1);
@@ -93,6 +100,9 @@ int main()
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = A(1);
+#if TEST_STD_VER >= 11
+ static_assert(noexcept(swap(f1, f2)), "" );
+#endif
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(*f1.target<int(*)(int)>() == g);
@@ -108,6 +118,9 @@ int main()
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = h;
+#if TEST_STD_VER >= 11
+ static_assert(noexcept(swap(f1, f2)), "" );
+#endif
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(*f1.target<int(*)(int)>() == g);
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
index 82a6f6c5215e..fd296a7367b8 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
@@ -16,6 +16,7 @@
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "count_new.hpp"
class A
@@ -49,6 +50,17 @@ int A::count = 0;
int g(int) {return 0;}
+#if TEST_STD_VER >= 11
+struct RValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) && {}
+};
+struct LValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) & {}
+};
+#endif
+
int main()
{
assert(globalMemCounter.checkOutstandingNewEq(0));
@@ -91,4 +103,13 @@ int main()
std::function <void()> f(static_cast<void (*)()>(0));
assert(!f);
}
+#if TEST_STD_VER >= 11
+ {
+ using Fn = std::function<void(int, int, int)>;
+ static_assert(std::is_constructible<Fn, LValueCallable&>::value, "");
+ static_assert(std::is_constructible<Fn, LValueCallable>::value, "");
+ static_assert(!std::is_constructible<Fn, RValueCallable&>::value, "");
+ static_assert(!std::is_constructible<Fn, RValueCallable>::value, "");
+ }
+#endif
}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
index 11716e7946b0..e927ad42c06b 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
@@ -19,6 +19,7 @@
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "count_new.hpp"
class A
@@ -52,6 +53,17 @@ int A::count = 0;
int g(int) {return 0;}
+#if TEST_STD_VER >= 11
+struct RValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) && {}
+};
+struct LValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) & {}
+};
+#endif
+
int main()
{
assert(globalMemCounter.checkOutstandingNewEq(0));
@@ -95,4 +107,13 @@ int main()
assert(f.target<int(*)(int)>() != 0);
f(1);
}
+#if TEST_STD_VER >= 11
+ {
+ using Fn = std::function<void(int, int, int)>;
+ static_assert(std::is_assignable<Fn&, LValueCallable&>::value, "");
+ static_assert(std::is_assignable<Fn&, LValueCallable>::value, "");
+ static_assert(!std::is_assignable<Fn&, RValueCallable&>::value, "");
+ static_assert(!std::is_assignable<Fn&, RValueCallable>::value, "");
+ }
+#endif
}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp
new file mode 100644
index 000000000000..f455f0311847
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+// XFAIL: c++98, c++03, c++11, c++14
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&);
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ std::function<int(int)> f(std::allocator_arg, std::allocator<int>());
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp
index f97e34d3f2cb..392dfc1993bc 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp
@@ -8,10 +8,13 @@
//===----------------------------------------------------------------------===//
// <functional>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
// class function<R(ArgTypes...)>
// template<class A> function(allocator_arg_t, const A&);
+//
+// This signature was removed in C++17
#include <functional>
#include <cassert>
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp
new file mode 100644
index 000000000000..24f7fceb877b
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+// XFAIL: c++98, c++03, c++11, c++14
+
+// class function<R(ArgTypes...)>
+
+// template<class F, class A> function(allocator_arg_t, const A&, F);
+//
+// This signature was removed in C++17
+
+#include <functional>
+#include <cassert>
+
+#include "test_macros.h"
+
+void foo(int) {}
+
+int main()
+{
+ std::function<void(int)> f(std::allocator_arg, std::allocator<int>(), foo);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
index 352ecfc602be..8d454723320c 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
// <functional>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
// class function<R(ArgTypes...)>
@@ -16,11 +17,24 @@
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "count_new.hpp"
#include "../function_types.h"
+
+#if TEST_STD_VER >= 11
+struct RValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) && {}
+};
+struct LValueCallable {
+ template <class ...Args>
+ void operator()(Args&&...) & {}
+};
+#endif
+
class DummyClass {};
template <class FuncType, class AllocType>
@@ -103,4 +117,14 @@ int main()
non_default_test_allocator<DummyClass> non_default_alloc(42);
test_for_alloc(non_default_alloc);
}
+#if TEST_STD_VER >= 11
+ {
+ using Fn = std::function<void(int, int, int)>;
+ static_assert(std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, LValueCallable&>::value, "");
+ static_assert(std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, LValueCallable>::value, "");
+ static_assert(!std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, RValueCallable&>::value, "");
+ static_assert(!std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, RValueCallable>::value, "");
+ }
+#endif
+
}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp
new file mode 100644
index 000000000000..9967457ff821
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+// XFAIL: c++98, c++03, c++11, c++14
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, const function&);
+//
+// This signature was removed in C++17
+
+
+#include <functional>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ typedef std::function<void(int)> F;
+ F f1;
+ F f2(std::allocator_arg, std::allocator<int>(), f1);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp
index 371eb98de1a9..718aa49341d2 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
// <functional>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
// class function<R(ArgTypes...)>
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp
new file mode 100644
index 000000000000..cc4ecce75138
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+// XFAIL: c++98, c++03, c++11, c++14
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, nullptr_t);
+//
+// This signature was removed in C++17
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ std::function<int(int)> f(std::allocator_arg, std::allocator<int>(), nullptr);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp
index 2350f92f0f89..354ad955f207 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp
@@ -8,10 +8,13 @@
//===----------------------------------------------------------------------===//
// <functional>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
// class function<R(ArgTypes...)>
// template<class A> function(allocator_arg_t, const A&, nullptr_t);
+//
+// This signature was removed in C++17
#include <functional>
#include <cassert>
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp
new file mode 100644
index 000000000000..cb9fb9afad2b
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+// XFAIL: c++98, c++03, c++11, c++14
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, function&&);
+//
+// This signature was removed in C++17
+
+#include <functional>
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+
+class A
+{
+ int data_[10];
+public:
+ static int count;
+
+ A()
+ {
+ ++count;
+ for (int i = 0; i < 10; ++i)
+ data_[i] = i;
+ }
+
+ A(const A&) {++count;}
+
+ ~A() {--count;}
+
+ int operator()(int i) const
+ {
+ for (int j = 0; j < 10; ++j)
+ i += data_[j];
+ return i;
+ }
+};
+
+int A::count = 0;
+
+int g(int) { return 0; }
+
+int main()
+{
+ {
+ std::function<int(int)> f = A();
+ std::function<int(int)> f2(std::allocator_arg, std::allocator<A>(), std::move(f));
+ }
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp
index 403d646f4216..e328481b274d 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp
@@ -8,12 +8,15 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
+// REQUIRES-ANY: c++11, c++14
// <functional>
// class function<R(ArgTypes...)>
// template<class A> function(allocator_arg_t, const A&, function&&);
+//
+// This signature was removed in C++17
#include <functional>
#include <memory>
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
index c91eaa2d5674..9b83ddecb974 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -16,94 +16,123 @@
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "count_new.hpp"
-class A
-{
- int data_[10];
+class A {
+ int data_[10];
+
public:
- static int count;
+ static int count;
- A()
- {
- ++count;
- for (int i = 0; i < 10; ++i)
- data_[i] = i;
- }
+ A() {
+ ++count;
+ for (int i = 0; i < 10; ++i)
+ data_[i] = i;
+ }
- A(const A&) {++count;}
+ A(const A &) { ++count; }
- ~A() {--count;}
+ ~A() { --count; }
- int operator()(int i) const
- {
- for (int j = 0; j < 10; ++j)
- i += data_[j];
- return i;
- }
+ int operator()(int i) const {
+ for (int j = 0; j < 10; ++j)
+ i += data_[j];
+ return i;
+ }
};
int A::count = 0;
-int g(int) {return 0;}
+int g0() { return 0; }
+int g(int) { return 0; }
+int g2(int, int) { return 2; }
+int g3(int, int, int) { return 3; }
-int main()
-{
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+int main() {
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
- assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<int (*)(int)>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f2.target<A>());
- assert(f2.target<int(*)(int)>() == 0);
- }
- assert(A::count == 0);
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ assert(f2.target<int (*)(int)>() == 0);
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f = g;
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(f.target<int(*)(int)>());
+ assert(f.target<int (*)(int)>());
assert(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(f2.target<int(*)(int)>());
+ assert(f2.target<int (*)(int)>());
assert(f2.target<A>() == 0);
- }
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f;
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<int (*)(int)>() == 0);
assert(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(f2.target<int(*)(int)>() == 0);
+ assert(f2.target<int (*)(int)>() == 0);
assert(f2.target<A>() == 0);
- }
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ }
+ {
+ typedef std::function<int()> Func;
+ Func f = g0;
+ Func& fr = (f = f);
+ assert(&fr == &f);
+ assert(*f.target<int(*)()>() == g0);
+ }
+ {
+ typedef std::function<int(int)> Func;
+ Func f = g;
+ Func& fr = (f = f);
+ assert(&fr == &f);
+ assert(*f.target<int(*)(int)>() == g);
+ }
+ {
+ typedef std::function<int(int, int)> Func;
+ Func f = g2;
+ Func& fr = (f = f);
+ assert(&fr == &f);
+ assert(*f.target<int(*)(int, int)>() == g2);
+ }
+ {
+ typedef std::function<int(int, int, int)> Func;
+ Func f = g3;
+ Func& fr = (f = f);
+ assert(&fr == &f);
+ assert(*f.target<int(*)(int, int, int)>() == g3);
+ }
+#if TEST_STD_VER >= 11
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
- assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<int (*)(int)>() == 0);
std::function<int(int)> f2;
f2 = std::move(f);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f2.target<A>());
- assert(f2.target<int(*)(int)>() == 0);
+ assert(f2.target<int (*)(int)>() == 0);
assert(f.target<A>() == 0);
- assert(f.target<int(*)(int)>() == 0);
- }
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ assert(f.target<int (*)(int)>() == 0);
+ }
+#endif
}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
index 387b371a9331..9d5681a3db76 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
@@ -132,7 +132,7 @@ int main()
assert(A::count == 1);
assert(f2.target<A>() == nullptr);
assert(f2.target<Ref>());
- assert(f.target<Ref>()); // f is unchanged because the target is small
+ LIBCPP_ASSERT(f.target<Ref>()); // f is unchanged because the target is small
}
{
// Test that moving a function constructed from a function pointer
@@ -146,7 +146,7 @@ int main()
std::function<int(int)> f2(std::move(f));
assert(f2.target<A>() == nullptr);
assert(f2.target<Ptr>());
- assert(f.target<Ptr>()); // f is unchanged because the target is small
+ LIBCPP_ASSERT(f.target<Ptr>()); // f is unchanged because the target is small
}
#endif // TEST_STD_VER >= 11
}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
index f94e689b2a6b..214c3f7c5d83 100644
--- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
@@ -18,46 +18,49 @@
#include "count_new.hpp"
-class A
-{
- int data_[10];
+class A {
+ int data_[10];
+
public:
- static int count;
+ static int count;
- explicit A(int j)
- {
- ++count;
- data_[0] = j;
- }
+ explicit A(int j) {
+ ++count;
+ data_[0] = j;
+ }
- A(const A& a)
- {
- ++count;
- for (int i = 0; i < 10; ++i)
- data_[i] = a.data_[i];
- }
+ A(const A &a) {
+ ++count;
+ for (int i = 0; i < 10; ++i)
+ data_[i] = a.data_[i];
+ }
- ~A() {--count;}
+ ~A() { --count; }
- int operator()(int i) const
- {
- for (int j = 0; j < 10; ++j)
- i += data_[j];
- return i;
- }
+ int operator()(int i) const {
+ for (int j = 0; j < 10; ++j)
+ i += data_[j];
+ return i;
+ }
+
+ int operator()() const { return -1; }
+ int operator()(int, int) const { return -2; }
+ int operator()(int, int, int) const { return -3; }
- int id() const {return data_[0];}
+ int id() const { return data_[0]; }
};
int A::count = 0;
-int g(int) {return 0;}
-int h(int) {return 1;}
+int g0() { return 0; }
+int g(int) { return 0; }
+int h(int) { return 1; }
+int g2(int, int) { return 2; }
+int g3(int, int, int) { return 3; }
-int main()
-{
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+int main() {
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = A(2);
assert(A::count == 2);
@@ -69,52 +72,122 @@ int main()
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f1.target<A>()->id() == 2);
assert(f2.target<A>()->id() == 1);
- }
- assert(A::count == 0);
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = g;
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1);
- assert(*f2.target<int(*)(int)>() == g);
+ assert(*f2.target<int (*)(int)>() == g);
f1.swap(f2);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
- assert(*f1.target<int(*)(int)>() == g);
+ assert(*f1.target<int (*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
- }
- assert(A::count == 0);
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = A(1);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
- assert(*f1.target<int(*)(int)>() == g);
+ assert(*f1.target<int (*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
f1.swap(f2);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1);
- assert(*f2.target<int(*)(int)>() == g);
- }
- assert(A::count == 0);
- assert(globalMemCounter.checkOutstandingNewEq(0));
- {
+ assert(*f2.target<int (*)(int)>() == g);
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = h;
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(*f1.target<int(*)(int)>() == g);
- assert(*f2.target<int(*)(int)>() == h);
+ assert(*f1.target<int (*)(int)>() == g);
+ assert(*f2.target<int (*)(int)>() == h);
f1.swap(f2);
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
- assert(*f1.target<int(*)(int)>() == h);
- assert(*f2.target<int(*)(int)>() == g);
+ assert(*f1.target<int (*)(int)>() == h);
+ assert(*f2.target<int (*)(int)>() == g);
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f1 = A(1);
+ assert(A::count == 1);
+ {
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
}
- assert(A::count == 0);
- assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(A::count == 1);
+ assert(f1.target<A>()->id() == 1);
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int()> f1 = g0;
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(*f1.target<int (*)()>() == g0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int, int)> f1 = g2;
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(*f1.target<int (*)(int, int)>() == g2);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int, int, int)> f1 = g3;
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(*f1.target<int (*)(int, int, int)>() == g3);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int()> f1 = A(1);
+ assert(A::count == 1);
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(A::count == 1);
+ assert(f1.target<A>()->id() == 1);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(A::count == 0);
+ {
+ std::function<int(int, int)> f1 = A(2);
+ assert(A::count == 1);
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(A::count == 1);
+ assert(f1.target<A>()->id() == 2);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(A::count == 0);
+ {
+ std::function<int(int, int, int)> f1 = A(3);
+ assert(A::count == 1);
+ DisableAllocationGuard guard;
+ ((void)guard);
+ f1.swap(f1);
+ assert(A::count == 1);
+ assert(f1.target<A>()->id() == 3);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(A::count == 0);
}