summaryrefslogtreecommitdiff
path: root/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
commit61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch)
treeec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con
parentf857581820d15e410e9945d2fcd5f7163be25a96 (diff)
Notes
Diffstat (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con')
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp90
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp98
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp29
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp27
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp106
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp124
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp25
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp68
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp118
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp109
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp23
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp24
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp23
-rw-r--r--test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp72
14 files changed, 936 insertions, 0 deletions
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
new file mode 100644
index 0000000000000..cd86e4cbf8ebe
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
@@ -0,0 +1,90 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// function(nullptr_t);
+
+#include <functional>
+#include <cassert>
+
+#include "count_new.hpp"
+
+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 foo(int) const {return 1;}
+};
+
+int A::count = 0;
+
+int g(int) {return 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(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<A>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f = (int (*)(int))0;
+ assert(!f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ }
+ {
+ std::function<int(const A*, int)> f = &A::foo;
+ assert(f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int (A::*)(int) const>() != 0);
+ }
+ {
+ std::function<void(int)> f(&g);
+ assert(f);
+ assert(f.target<int(*)(int)>() != 0);
+ f(1);
+ }
+}
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
new file mode 100644
index 0000000000000..11716e7946b04
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
@@ -0,0 +1,98 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// template<class F>
+// requires CopyConstructible<F> && Callable<F, ArgTypes..>
+// && Convertible<Callable<F, ArgTypes...>::result_type
+// operator=(F f);
+
+#include <functional>
+#include <cassert>
+
+#include "count_new.hpp"
+
+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 foo(int) const {return 1;}
+};
+
+int A::count = 0;
+
+int g(int) {return 0;}
+
+int main()
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f;
+ f = A();
+ assert(A::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f.target<A>());
+ assert(f.target<int(*)(int)>() == 0);
+ }
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f;
+ f = g;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>());
+ assert(f.target<A>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f;
+ f = (int (*)(int))0;
+ assert(!f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ }
+ {
+ std::function<int(const A*, int)> f;
+ f = &A::foo;
+ assert(f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int (A::*)(int) const>() != 0);
+ }
+ {
+ std::function<void(int)> f;
+ f = &g;
+ assert(f);
+ assert(f.target<int(*)(int)>() != 0);
+ f(1);
+ }
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp
new file mode 100644
index 0000000000000..c8f4178a26bdd
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// class function<R(ArgTypes...)>
+
+// template<class F> function(F);
+
+// Allow incomplete argument types in the __is_callable check
+
+#include <functional>
+
+struct X{
+ typedef std::function<void(X&)> callback_type;
+ virtual ~X() {}
+private:
+ callback_type _cb;
+};
+
+int main()
+{
+}
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
new file mode 100644
index 0000000000000..f97e34d3f2cbe
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.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>
+
+// 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, bare_allocator<int>());
+ assert(!f);
+ }
+}
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
new file mode 100644
index 0000000000000..352ecfc602be4
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
@@ -0,0 +1,106 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// template<class F, class A> function(allocator_arg_t, const A&, F);
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "test_allocator.h"
+#include "count_new.hpp"
+#include "../function_types.h"
+
+class DummyClass {};
+
+template <class FuncType, class AllocType>
+void test_FunctionObject(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ FunctionObject target;
+ assert(FunctionObject::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ std::function<FuncType> f2(std::allocator_arg, alloc, target);
+ assert(FunctionObject::count == 2);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f2.template target<FunctionObject>());
+ assert(f2.template target<FuncType>() == 0);
+ assert(f2.template target<FuncType*>() == 0);
+ }
+ assert(FunctionObject::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+
+template <class FuncType, class AllocType>
+void test_FreeFunction(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ FuncType* target = &FreeFunction;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ std::function<FuncType> f2(std::allocator_arg, alloc, target);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.template target<FuncType*>());
+ assert(*f2.template target<FuncType*>() == target);
+ assert(f2.template target<FuncType>() == 0);
+ assert(f2.template target<DummyClass>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+template <class TargetType, class FuncType, class AllocType>
+void test_MemFunClass(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ TargetType target = &MemFunClass::foo;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ std::function<FuncType> f2(std::allocator_arg, alloc, target);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.template target<TargetType>());
+ assert(*f2.template target<TargetType>() == target);
+ assert(f2.template target<FuncType*>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+template <class Alloc>
+void test_for_alloc(Alloc& alloc) {
+ test_FunctionObject<int()>(alloc);
+ test_FunctionObject<int(int)>(alloc);
+ test_FunctionObject<int(int, int)>(alloc);
+ test_FunctionObject<int(int, int, int)>(alloc);
+
+ test_FreeFunction<int()>(alloc);
+ test_FreeFunction<int(int)>(alloc);
+ test_FreeFunction<int(int, int)>(alloc);
+ test_FreeFunction<int(int, int, int)>(alloc);
+
+ test_MemFunClass<int(MemFunClass::*)() const, int(MemFunClass&)>(alloc);
+ test_MemFunClass<int(MemFunClass::*)(int) const, int(MemFunClass&, int)>(alloc);
+ test_MemFunClass<int(MemFunClass::*)(int, int) const, int(MemFunClass&, int, int)>(alloc);
+}
+
+int main()
+{
+ {
+ bare_allocator<DummyClass> bare_alloc;
+ test_for_alloc(bare_alloc);
+ }
+ {
+ non_default_test_allocator<DummyClass> non_default_alloc(42);
+ test_for_alloc(non_default_alloc);
+ }
+}
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
new file mode 100644
index 0000000000000..371eb98de1a9b
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp
@@ -0,0 +1,124 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, const function&);
+
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "test_allocator.h"
+#include "count_new.hpp"
+#include "../function_types.h"
+
+class DummyClass {};
+
+template <class FuncType, class AllocType>
+void test_FunctionObject(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ // Construct function from FunctionObject.
+ std::function<FuncType> f = FunctionObject();
+ assert(FunctionObject::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f.template target<FunctionObject>());
+ assert(f.template target<FuncType>() == 0);
+ assert(f.template target<FuncType*>() == 0);
+ // Copy function with allocator
+ std::function<FuncType> f2(std::allocator_arg, alloc, f);
+ assert(FunctionObject::count == 2);
+ assert(globalMemCounter.checkOutstandingNewEq(2));
+ assert(f2.template target<FunctionObject>());
+ assert(f2.template target<FuncType>() == 0);
+ assert(f2.template target<FuncType*>() == 0);
+ }
+ assert(FunctionObject::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+template <class FuncType, class AllocType>
+void test_FreeFunction(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ // Construct function from function pointer.
+ FuncType* target = &FreeFunction;
+ std::function<FuncType> f = target;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.template target<FuncType*>());
+ assert(*f.template target<FuncType*>() == target);
+ assert(f.template target<FuncType>() == 0);
+ // Copy function with allocator
+ std::function<FuncType> f2(std::allocator_arg, alloc, f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.template target<FuncType*>());
+ assert(*f2.template target<FuncType*>() == target);
+ assert(f2.template target<FuncType>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+template <class TargetType, class FuncType, class AllocType>
+void test_MemFunClass(AllocType& alloc)
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ // Construct function from function pointer.
+ TargetType target = &MemFunClass::foo;
+ std::function<FuncType> f = target;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.template target<TargetType>());
+ assert(*f.template target<TargetType>() == target);
+ assert(f.template target<FuncType*>() == 0);
+ // Copy function with allocator
+ std::function<FuncType> f2(std::allocator_arg, alloc, f);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.template target<TargetType>());
+ assert(*f2.template target<TargetType>() == target);
+ assert(f2.template target<FuncType*>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+}
+
+template <class Alloc>
+void test_for_alloc(Alloc& alloc)
+{
+ // Large FunctionObject -- Allocation should occur
+ test_FunctionObject<int()>(alloc);
+ test_FunctionObject<int(int)>(alloc);
+ test_FunctionObject<int(int, int)>(alloc);
+ test_FunctionObject<int(int, int, int)>(alloc);
+ // Free function -- No allocation should occur
+ test_FreeFunction<int()>(alloc);
+ test_FreeFunction<int(int)>(alloc);
+ test_FreeFunction<int(int, int)>(alloc);
+ test_FreeFunction<int(int, int, int)>(alloc);
+ // Member function -- No allocation should occur.
+ test_MemFunClass<int(MemFunClass::*)() const, int(MemFunClass&)>(alloc);
+ test_MemFunClass<int(MemFunClass::*)(int) const, int(MemFunClass&, int)>(alloc);
+ test_MemFunClass<int(MemFunClass::*)(int, int) const, int(MemFunClass&, int, int)>(alloc);
+}
+
+int main()
+{
+ {
+ bare_allocator<DummyClass> alloc;
+ test_for_alloc(alloc);
+ }
+ {
+ non_default_test_allocator<DummyClass> alloc(42);
+ test_for_alloc(alloc);
+ }
+}
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
new file mode 100644
index 0000000000000..2350f92f0f893
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.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>
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, nullptr_t);
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ std::function<int(int)> f(std::allocator_arg, bare_allocator<int>(), nullptr);
+ assert(!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
new file mode 100644
index 0000000000000..aa6b743b5236b
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// template<class A> function(allocator_arg_t, const A&, function&&);
+
+#include <functional>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "count_new.hpp"
+
+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 main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ 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);
+ std::function<int(int)> f2(std::allocator_arg, bare_allocator<A>(), std::move(f));
+ assert(A::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f2.target<A>());
+ assert(f2.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ assert(f.target<int(*)(int)>() == 0);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp
new file mode 100644
index 0000000000000..f603da9dd1319
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp
@@ -0,0 +1,118 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// function(const function& f);
+
+#include <functional>
+#include <cstdlib>
+#include <cassert>
+
+#include "count_new.hpp"
+
+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()
+{
+ 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);
+ std::function<int(int)> 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));
+ {
+ std::function<int(int)> f = g;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>());
+ assert(f.target<A>() == 0);
+ std::function<int(int)> f2 = f;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.target<int(*)(int)>());
+ assert(f2.target<A>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ std::function<int(int)> f2 = f;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f2.target<int(*)(int)>() == 0);
+ assert(f2.target<A>() == 0);
+ }
+ {
+ std::function<int(int)> f;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ assert(!f);
+ std::function<long(int)> g = f;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(g.target<long(*)(int)>() == 0);
+ assert(g.target<A>() == 0);
+ assert(!g);
+ }
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ 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);
+ std::function<int(int)> f2 = std::move(f);
+ assert(A::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f2.target<A>());
+ assert(f2.target<int(*)(int)>() == 0);
+ assert(f.target<A>() == 0);
+ assert(f.target<int(*)(int)>() == 0);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
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
new file mode 100644
index 0000000000000..c91eaa2d56744
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// function& operator=(const function& f);
+
+#include <functional>
+#include <cassert>
+
+#include "count_new.hpp"
+
+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()
+{
+ 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);
+ 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));
+ {
+ std::function<int(int)> f = g;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ 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<A>() == 0);
+ }
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f;
+ assert(globalMemCounter.checkOutstandingNewEq(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<A>() == 0);
+ }
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ 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);
+ 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(f.target<A>() == 0);
+ assert(f.target<int(*)(int)>() == 0);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp
new file mode 100644
index 0000000000000..83d61b6b2d89e
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// explicit function();
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ std::function<int(int)> f;
+ assert(!f);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp
new file mode 100644
index 0000000000000..7099c45fab81f
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R()>
+
+// template<class F> function(F);
+
+#define _LIBCPP_HAS_NO_VARIADICS
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ std::function<void()> f(static_cast<void(*)()>(0));
+ assert(!f);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp
new file mode 100644
index 0000000000000..f0d6402d185e4
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// function(nullptr_t);
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ std::function<int(int)> f(nullptr);
+ assert(!f);
+}
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
new file mode 100644
index 0000000000000..9b2482fb9d544
--- /dev/null
+++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class function<R(ArgTypes...)>
+
+// function& operator=(nullptr_t);
+
+#include <functional>
+#include <cassert>
+
+#include "count_new.hpp"
+
+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()
+{
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ {
+ std::function<int(int)> f = A();
+ assert(A::count == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(f.target<A>());
+ f = nullptr;
+ assert(A::count == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<A>() == 0);
+ }
+ {
+ std::function<int(int)> f = g;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>());
+ assert(f.target<A>() == 0);
+ f = nullptr;
+ assert(globalMemCounter.checkOutstandingNewEq(0));
+ assert(f.target<int(*)(int)>() == 0);
+ }
+}