diff options
Diffstat (limited to 'libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con')
14 files changed, 990 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp new file mode 100644 index 00000000000..3a43be73f7a --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f = (int (*)(int))0; + assert(!f); + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f = &A::foo; + assert(f); + assert(new_called == 0); + assert(f.target<int (A::*)(int) const>() != 0); + } +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp new file mode 100644 index 00000000000..ba65cd3330b --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f; + f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f; + f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + f = (int (*)(int))0; + assert(!f); + assert(new_called == 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(new_called == 0); + assert(f.target<int (A::*)(int) const>() != 0); + } +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp new file mode 100644 index 00000000000..c8f4178a26b --- /dev/null +++ b/libcxx/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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp new file mode 100644 index 00000000000..4feac30c300 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.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&); + +#include <functional> +#include <cassert> + +#include "test_allocator.h" + +int main() +{ + std::function<int(int)> f(std::allocator_arg, test_allocator<int>()); + assert(!f); +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp new file mode 100644 index 00000000000..599092258da --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_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...)> + +// template<class F, class A> function(allocator_arg_t, const A&, F); + +#include <functional> +#include <cassert> + +#include "test_allocator.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 foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +class Foo { +public: + void bar(int k) { } +}; + +int main() +{ + { + std::function<int(int)> f(std::allocator_arg, test_allocator<A>(), A()); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + { + std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(), g); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + { + std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(), + (int (*)(int))0); + assert(!f); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f(std::allocator_arg, + test_allocator<int(A::*)(int)const>(), + &A::foo); + assert(f); + assert(f.target<int (A::*)(int) const>() != 0); + } + { + Foo f; + std::function<void(int)> fun = std::bind(&Foo::bar, &f, std::placeholders::_1); + fun(10); + } +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp new file mode 100644 index 00000000000..38e65fc845f --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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&); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +#include "test_allocator.h" + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f); + assert(A::count == 2); + assert(new_called == 2); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f); + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + assert(new_called == 0); + non_default_test_allocator<std::function<int(int)>> al(1); + std::function<int(int)> f2(std::allocator_arg, al, g); + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f); + assert(new_called == 0); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp new file mode 100644 index 00000000000..956136be021 --- /dev/null +++ b/libcxx/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 "test_allocator.h" + +int main() +{ + std::function<int(int)> f(std::allocator_arg, test_allocator<int>(), nullptr); + assert(!f); +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp new file mode 100644 index 00000000000..2180b8936d7 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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&&); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <cassert> + +#include "test_allocator.h" + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), std::move(f)); + assert(A::count == 1); + assert(new_called == 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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp new file mode 100644 index 00000000000..2fbd7cfa9fb --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp @@ -0,0 +1,133 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = f; + assert(A::count == 2); + assert(new_called == 2); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(!f); + std::function<long(int)> g = f; + assert(new_called == 0); + assert(g.target<long(*)(int)>() == 0); + assert(g.target<A>() == 0); + assert(!g); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = std::move(f); + assert(A::count == 1); + assert(new_called == 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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp new file mode 100644 index 00000000000..cfa79e24401 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(A::count == 2); + assert(new_called == 2); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 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(new_called == 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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp new file mode 100644 index 00000000000..83d61b6b2d8 --- /dev/null +++ b/libcxx/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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp new file mode 100644 index 00000000000..7099c45fab8 --- /dev/null +++ b/libcxx/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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp new file mode 100644 index 00000000000..f0d6402d185 --- /dev/null +++ b/libcxx/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/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp new file mode 100644 index 00000000000..b8c597b63ce --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +// UNSUPPORTED: asan, msan + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +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(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + f = nullptr; + assert(A::count == 0); + assert(new_called == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + f = nullptr; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + } +} |