diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 18:01:01 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 18:01:01 +0000 |
| commit | b7332b04df5d50c92640c74cfeb138ecb7e3f7ae (patch) | |
| tree | b1b49faa0cab1482905e0cda6f0ee5d97e3fe08f /test/std/utilities/function.objects/func.wrap/func.wrap.func | |
| parent | 6012fe9abb1f01b1b5b4ca908464804c21ff8602 (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func')
34 files changed, 0 insertions, 2956 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 deleted file mode 100644 index e156fa966ac5..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.fail.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 7d3a5dec4ef6..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <functional> - -// See https://bugs.llvm.org/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 ); -#if TEST_STD_VER <= 14 - S f2(std::allocator_arg, std::allocator<int>{}, s); -#endif -} 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 deleted file mode 100644 index 1a9206e0e7f3..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp +++ /dev/null @@ -1,136 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 <MoveConstructible R, MoveConstructible ... 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 -{ - int data_[10]; -public: - static int count; - - 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() {--count;} - - int operator()(int i) const - { - for (int j = 0; j < 10; ++j) - i += data_[j]; - return i; - } - - int id() const {return data_[0];} -}; - -int A::count = 0; - -int g(int) {return 0;} -int h(int) {return 1;} - -int main() -{ - assert(globalMemCounter.checkOutstandingNewEq(0)); - { - 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); - assert(f2.target<A>()->id() == 2); - swap(f1, f2); - assert(A::count == 2); - assert(globalMemCounter.checkOutstandingNewEq(2)); - assert(f1.target<A>()->id() == 2); - assert(f2.target<A>()->id() == 1); - } - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); - { - 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); - assert(*f2.target<int(*)(int)>() == g); - swap(f1, f2); - assert(A::count == 1); - assert(globalMemCounter.checkOutstandingNewEq(1)); - assert(*f1.target<int(*)(int)>() == g); - assert(f2.target<A>()->id() == 1); - } - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); - { - 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); - assert(f2.target<A>()->id() == 1); - swap(f1, 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)); - { - 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); - assert(*f2.target<int(*)(int)>() == h); - swap(f1, f2); - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); - assert(*f1.target<int(*)(int)>() == h); - assert(*f2.target<int(*)(int)>() == g); - } - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp deleted file mode 100644 index 829763f79d82..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 operator bool() const - -#include <functional> -#include <cassert> - -int g(int) {return 0;} - -int main() -{ - { - std::function<int(int)> f; - assert(!f); - f = g; - assert(f); - } -} 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 deleted file mode 100644 index fd296a7367b8..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ /dev/null @@ -1,115 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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(F); - -#include <functional> -#include <cassert> - -#include "test_macros.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 foo(int) const {return 1;} -}; - -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)); - { - 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); - } - { - 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 deleted file mode 100644 index e927ad42c06b..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ /dev/null @@ -1,119 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 "test_macros.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 foo(int) const {return 1;} -}; - -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)); - { - 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); - } -#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/F_incomplete.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp deleted file mode 100644 index 75e2ecac3c41..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> -#include <cassert> - -struct X{ - typedef std::function<void(X&)> callback_type; - virtual ~X() {} -private: - callback_type _cb; -}; - -struct IncompleteReturnType { - std::function<IncompleteReturnType ()> fn; -}; - - -int called = 0; -IncompleteReturnType test_fn() { - ++called; - IncompleteReturnType I; - return I; -} - -// See llvm.org/PR34298 -void test_pr34298() -{ - static_assert(std::is_copy_constructible<IncompleteReturnType>::value, ""); - static_assert(std::is_copy_assignable<IncompleteReturnType>::value, ""); - { - IncompleteReturnType X; - X.fn = test_fn; - const IncompleteReturnType& CX = X; - IncompleteReturnType X2 = CX; - assert(X2.fn); - assert(called == 0); - X2.fn(); - assert(called == 1); - } - { - IncompleteReturnType Empty; - IncompleteReturnType X2 = Empty; - assert(!X2.fn); - } -} - -int main() { - test_pr34298(); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp deleted file mode 100644 index 3affd984af60..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp +++ /dev/null @@ -1,247 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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(Fp); - -// Ensure that __not_null works for all function types. -// See https://bugs.llvm.org/show_bug.cgi?id=23589 - -//------------------------------------------------------------------------------ -// TESTING std::function<...>::__not_null(Callable) -// -// Concerns: -// 1) The call __not_null(Callable) is well formed and correct for each -// possible 'Callable' type category. These categories include: -// 1a) function pointers -// 1b) member function pointer -// 1c) member data pointer -// 1d) callable class type -// 1e) lambdas -// Categories 1a, 1b, and 1c are 'Nullable' types. Only objects of these -// types can be null. The other categories are not tested here. -// 3) '__not_null(Callable)' is well formed when the call signature includes -// varargs. -// 4) '__not_null(Callable)' works for Callable types with all arities less -// than or equal to 3 in C++03. -// 5) '__not_null(Callable)' works when 'Callable' is a member function -// pointer to a cv or ref qualified function type. -// -// Plan: -// 1 For categories 1a, 1b and 1c define a set of -// 'Callable' objects for this category. This set should include examples -// of arity 0, 1, 2 and possible 3 including versions with varargs as the -// last parameter. -// -// 2 For each 'Callable' object in categories 1a, 1b and 1c do the following. -// -// 1 Define a type 'std::function<Sig>' as 'F' where 'Sig' is compatible with -// the signature of the 'Callable' object. -// -// 2 Create an object of type 'F' using a null pointer of type 'Callable'. -// Check that 'F.target<Callable>()' is null. -// -// 3 Create an object of type 'F' that is not null. Check that -// 'F.target<Callable>()' is not null and is equal to the original -// argument. - -#include <functional> -#include <type_traits> -#include <cassert> - -#include "test_macros.h" - -/////////////////////////////////////////////////////////////////////////////// -int foo() { return 42; } -int foo(int) { return 42; } -int foo(int, int) { return 42; } -int foo(int, int, int) { return 42; } - -int foo(...) { return 42; } -int foo(int, ...) { return 42; } -int foo(int, int, ...) { return 42; } -int foo(int, int, int, ...) { return 42; } - -/////////////////////////////////////////////////////////////////////////////// -struct MemFun03 { - int foo() { return 42; } - int foo() const { return 42; } - int foo() volatile { return 42; } - int foo() const volatile { return 42; } - - int foo(int) { return 42; } - int foo(int) const { return 42; } - int foo(int) volatile { return 42; } - int foo(int) const volatile { return 42; } - - int foo(int, int) { return 42; } - int foo(int, int) const { return 42; } - int foo(int, int) volatile { return 42; } - int foo(int, int) const volatile { return 42; } - - int foo(int, int, int) { return 42; } - int foo(int, int, int) const { return 42; } - int foo(int, int, int) volatile { return 42; } - int foo(int, int, int) const volatile { return 42; } - - int foo(...) { return 42; } - int foo(...) const { return 42; } - int foo(...) volatile { return 42; } - int foo(...) const volatile { return 42; } - - int foo(int, ...) { return 42; } - int foo(int, ...) const { return 42; } - int foo(int, ...) volatile { return 42; } - int foo(int, ...) const volatile { return 42; } - - int foo(int, int, ...) { return 42; } - int foo(int, int, ...) const { return 42; } - int foo(int, int, ...) volatile { return 42; } - int foo(int, int, ...) const volatile { return 42; } - - int foo(int, int, int, ...) { return 42; } - int foo(int, int, int, ...) const { return 42; } - int foo(int, int, int, ...) volatile { return 42; } - int foo(int, int, int, ...) const volatile { return 42; } -}; - -#if TEST_STD_VER >= 11 -struct MemFun11 { - int foo() & { return 42; } - int foo() const & { return 42; } - int foo() volatile & { return 42; } - int foo() const volatile & { return 42; } - - int foo(...) & { return 42; } - int foo(...) const & { return 42; } - int foo(...) volatile & { return 42; } - int foo(...) const volatile & { return 42; } - - int foo() && { return 42; } - int foo() const && { return 42; } - int foo() volatile && { return 42; } - int foo() const volatile && { return 42; } - - int foo(...) && { return 42; } - int foo(...) const && { return 42; } - int foo(...) volatile && { return 42; } - int foo(...) const volatile && { return 42; } -}; -#endif // TEST_STD_VER >= 11 - -struct MemData { - int foo; -}; - -// Create a non-null free function by taking the address of -// &static_cast<Tp&>(foo); -template <class Tp> -struct Creator { - static Tp create() { - return &foo; - } -}; - -// Create a non-null member pointer. -template <class Ret, class Class> -struct Creator<Ret Class::*> { - typedef Ret Class::*ReturnType; - static ReturnType create() { - return &Class::foo; - } -}; - -template <class TestFn, class Fn> -void test_imp() { - { // Check that the null value is detected - TestFn tf = nullptr; - std::function<Fn> f = tf; - assert(f.template target<TestFn>() == nullptr); - } - { // Check that the non-null value is detected. - TestFn tf = Creator<TestFn>::create(); - assert(tf != nullptr); - std::function<Fn> f = tf; - assert(f.template target<TestFn>() != nullptr); - assert(*f.template target<TestFn>() == tf); - } -} - -void test_func() { - test_imp<int(*)(), int()>(); - test_imp<int(*)(...), int()>(); - test_imp<int(*)(int), int(int)>(); - test_imp<int(*)(int, ...), int(int)>(); - test_imp<int(*)(int, int), int(int, int)>(); - test_imp<int(*)(int, int, ...), int(int, int)>(); - test_imp<int(*)(int, int, int), int(int, int, int)>(); - test_imp<int(*)(int, int, int, ...), int(int, int, int)>(); -} - -void test_mf() { - test_imp<int(MemFun03::*)(), int(MemFun03&)>(); - test_imp<int(MemFun03::*)(...), int(MemFun03&)>(); - test_imp<int(MemFun03::*)() const, int(MemFun03&)>(); - test_imp<int(MemFun03::*)(...) const, int(MemFun03&)>(); - test_imp<int(MemFun03::*)() volatile, int(MemFun03&)>(); - test_imp<int(MemFun03::*)(...) volatile, int(MemFun03&)>(); - test_imp<int(MemFun03::*)() const volatile, int(MemFun03&)>(); - test_imp<int(MemFun03::*)(...) const volatile, int(MemFun03&)>(); - - test_imp<int(MemFun03::*)(int), int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int, ...), int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int) const, int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int, ...) const, int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int) volatile, int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int, ...) volatile, int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int) const volatile, int(MemFun03&, int)>(); - test_imp<int(MemFun03::*)(int, ...) const volatile, int(MemFun03&, int)>(); - - test_imp<int(MemFun03::*)(int, int), int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int, ...), int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int) const, int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int, ...) const, int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int) volatile, int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int, ...) volatile, int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int) const volatile, int(MemFun03&, int, int)>(); - test_imp<int(MemFun03::*)(int, int, ...) const volatile, int(MemFun03&, int, int)>(); - -#if TEST_STD_VER >= 11 - test_imp<int(MemFun11::*)() &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)(...) &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)() const &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)(...) const &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)() volatile &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)(...) volatile &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)() const volatile &, int(MemFun11&)>(); - test_imp<int(MemFun11::*)(...) const volatile &, int(MemFun11&)>(); - - test_imp<int(MemFun11::*)() &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)(...) &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)() const &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)(...) const &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)() volatile &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)(...) volatile &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)() const volatile &&, int(MemFun11&&)>(); - test_imp<int(MemFun11::*)(...) const volatile &&, int(MemFun11&&)>(); -#endif -} - -void test_md() { - test_imp<int MemData::*, int(MemData&)>(); -} - -int main() { - test_func(); - test_mf(); - test_md(); -} 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 deleted file mode 100644 index f455f0311847..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index adc7856357e7..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> -// REQUIRES: 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> - -#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.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp deleted file mode 100644 index b23153465168..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 8a2a12e0f789..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp +++ /dev/null @@ -1,130 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> -// REQUIRES: c++98 || c++03 || c++11 || c++14 - -// class function<R(ArgTypes...)> - -// template<class F, class A> function(allocator_arg_t, const A&, F); - -#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> -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); - } -#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 deleted file mode 100644 index 2e4633b11693..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 8b0e831287a5..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ /dev/null @@ -1,125 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> -// REQUIRES: c++98 || c++03 || c++11 || c++14 - -// 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.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp deleted file mode 100644 index cc4ecce75138..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 943e170878f2..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> -// REQUIRES: 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, 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.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp deleted file mode 100644 index cb9fb9afad2b..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 3e5435da1a16..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ /dev/null @@ -1,109 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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: 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> -#include <cassert> - -#include "test_macros.h" -#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 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(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); - } - assert(globalMemCounter.checkOutstandingNewEq(0)); - { - // Test that moving a function constructed from a reference wrapper - // is done without allocating. - DisableAllocationGuard g; - using Ref = std::reference_wrapper<A>; - A a; - Ref aref(a); - std::function<int(int)> f(aref); - assert(A::count == 1); - assert(f.target<A>() == nullptr); - assert(f.target<Ref>()); - std::function<int(int)> f2(std::allocator_arg, std::allocator<void>{}, - std::move(f)); - 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 - } - { - // Test that moving a function constructed from a function pointer - // is done without allocating - DisableAllocationGuard guard; - using Ptr = int(*)(int); - Ptr p = g; - std::function<int(int)> f(p); - assert(f.target<A>() == nullptr); - assert(f.target<Ptr>()); - std::function<int(int)> f2(std::allocator_arg, std::allocator<void>(), - std::move(f)); - assert(f2.target<A>() == nullptr); - assert(f2.target<Ptr>()); - assert(f.target<Ptr>()); // f is unchanged because the target is small - } -} 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 deleted file mode 100644 index 1c2be02c6212..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ /dev/null @@ -1,138 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 "test_macros.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 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)); - { - 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); - } - { - typedef std::function<int()> Func; - Func f = g0; - Func& fr = (f = (Func &)f); - assert(&fr == &f); - assert(*f.target<int(*)()>() == g0); - } - { - typedef std::function<int(int)> Func; - Func f = g; - Func& fr = (f = (Func &)f); - assert(&fr == &f); - assert(*f.target<int(*)(int)>() == g); - } - { - typedef std::function<int(int, int)> Func; - Func f = g2; - Func& fr = (f = (Func &)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 = (Func &)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); - 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 -} 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 deleted file mode 100644 index e9b399a2edd2..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp +++ /dev/null @@ -1,165 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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); -// function(function&& f); // noexcept in C++20 - -#include <functional> -#include <memory> -#include <cstdlib> -#include <cassert> - -#include "test_macros.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 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); - } -#if TEST_STD_VER >= 11 - assert(globalMemCounter.checkOutstandingNewEq(0)); - { // Test rvalue references - std::function<int(int)> f = A(); - assert(A::count == 1); - assert(globalMemCounter.checkOutstandingNewEq(1)); - assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); - LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#if TEST_STD_VER > 17 - ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#endif - 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); - } - assert(globalMemCounter.checkOutstandingNewEq(0)); - { - // Test that moving a function constructed from a reference wrapper - // is done without allocating. - DisableAllocationGuard g; - using Ref = std::reference_wrapper<A>; - A a; - Ref aref(a); - std::function<int(int)> f(aref); - assert(A::count == 1); - assert(f.target<A>() == nullptr); - assert(f.target<Ref>()); - LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#if TEST_STD_VER > 17 - ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#endif - std::function<int(int)> f2(std::move(f)); - assert(A::count == 1); - assert(f2.target<A>() == nullptr); - assert(f2.target<Ref>()); - LIBCPP_ASSERT(f.target<Ref>()); // f is unchanged because the target is small - } - { - // Test that moving a function constructed from a function pointer - // is done without allocating - DisableAllocationGuard guard; - using Ptr = int(*)(int); - Ptr p = g; - std::function<int(int)> f(p); - assert(f.target<A>() == nullptr); - assert(f.target<Ptr>()); - LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#if TEST_STD_VER > 17 - ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); -#endif - std::function<int(int)> f2(std::move(f)); - assert(f2.target<A>() == nullptr); - assert(f2.target<Ptr>()); - 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.con/default.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp deleted file mode 100644 index 83d61b6b2d89..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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/move_reentrant.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp deleted file mode 100644 index 0813c48f322e..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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=(function &&); - -#include <functional> -#include <cassert> - -#include "test_macros.h" - -struct A -{ - static std::function<void()> global; - static bool cancel; - - ~A() { - DoNotOptimize(cancel); - if (cancel) - global = std::function<void()>(nullptr); - } - void operator()() {} -}; - -std::function<void()> A::global; -bool A::cancel = false; - -int main() -{ - A::global = A(); - assert(A::global.target<A>()); - - // Check that we don't recurse in A::~A(). - A::cancel = true; - A::global = std::function<void()>(nullptr); - assert(!A::global.target<A>()); -} 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 deleted file mode 100644 index f0d6402d185e..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index 9b2482fb9d54..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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); - } -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp deleted file mode 100644 index eeb181928eaf..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 "test_macros.h" - -struct A -{ - static std::function<void()> global; - static bool cancel; - - ~A() { - DoNotOptimize(cancel); - if (cancel) - global = nullptr; - } - void operator()() {} -}; - -std::function<void()> A::global; -bool A::cancel = false; - -int main() -{ - A::global = A(); - assert(A::global.target<A>()); - - // Check that we don't recurse in A::~A(). - A::cancel = true; - A::global = nullptr; - assert(!A::global.target<A>()); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp deleted file mode 100644 index 61eda7244d3b..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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...)> - -// R operator()(ArgTypes... args) const - -#include <functional> -#include <cassert> - -// member data pointer: cv qualifiers should transfer from argument to return type - -struct A_int_1 -{ - A_int_1() : data_(5) {} - - int data_; -}; - -void -test_int_1() -{ - // member data pointer - { - int A_int_1::*fp = &A_int_1::data_; - A_int_1 a; - std::function<int& (const A_int_1*)> r2(fp); - const A_int_1* ap = &a; - assert(r2(ap) == 6); - r2(ap) = 7; - assert(r2(ap) == 7); - } -} - -int main() -{ - test_int_1(); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp deleted file mode 100644 index cc4315c14422..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp +++ /dev/null @@ -1,413 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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...)> - -// R operator()(ArgTypes... args) const - -#include <functional> -#include <cassert> - - -int count = 0; - - -// 0 args, return int - -int f_int_0() -{ - return 3; -} - -struct A_int_0 -{ - int operator()() {return 4;} -}; - -void test_int_0() -{ - // function - { - std::function<int ()> r1(f_int_0); - assert(r1() == 3); - } - // function pointer - { - int (*fp)() = f_int_0; - std::function<int ()> r1(fp); - assert(r1() == 3); - } - // functor - { - A_int_0 a0; - std::function<int ()> r1(a0); - assert(r1() == 4); - } -} - - -// 0 args, return void - -void f_void_0() -{ - ++count; -} - -struct A_void_0 -{ - void operator()() {++count;} -}; - -void -test_void_0() -{ - int save_count = count; - // function - { - std::function<void ()> r1(f_void_0); - r1(); - assert(count == save_count+1); - save_count = count; - } - // function pointer - { - void (*fp)() = f_void_0; - std::function<void ()> r1(fp); - r1(); - assert(count == save_count+1); - save_count = count; - } - // functor - { - A_void_0 a0; - std::function<void ()> r1(a0); - r1(); - assert(count == save_count+1); - save_count = count; - } -} - -// 1 arg, return void - -void f_void_1(int i) -{ - count += i; -} - -struct A_void_1 -{ - void operator()(int i) - { - count += i; - } - - void mem1() {++count;} - void mem2() const {++count;} -}; - -void -test_void_1() -{ - int save_count = count; - // function - { - std::function<void (int)> r1(f_void_1); - int i = 2; - r1(i); - assert(count == save_count+2); - save_count = count; - } - // function pointer - { - void (*fp)(int) = f_void_1; - std::function<void (int)> r1(fp); - int i = 3; - r1(i); - assert(count == save_count+3); - save_count = count; - } - // functor - { - A_void_1 a0; - std::function<void (int)> r1(a0); - int i = 4; - r1(i); - assert(count == save_count+4); - save_count = count; - } - // member function pointer - { - void (A_void_1::*fp)() = &A_void_1::mem1; - std::function<void (A_void_1)> r1(fp); - A_void_1 a; - r1(a); - assert(count == save_count+1); - save_count = count; - A_void_1* ap = &a; - std::function<void (A_void_1*)> r2 = fp; - r2(ap); - assert(count == save_count+1); - save_count = count; - } - // const member function pointer - { - void (A_void_1::*fp)() const = &A_void_1::mem2; - std::function<void (A_void_1)> r1(fp); - A_void_1 a; - r1(a); - assert(count == save_count+1); - save_count = count; - std::function<void (A_void_1*)> r2(fp); - A_void_1* ap = &a; - r2(ap); - assert(count == save_count+1); - save_count = count; - } -} - -// 1 arg, return int - -int f_int_1(int i) -{ - return i + 1; -} - -struct A_int_1 -{ - A_int_1() : data_(5) {} - int operator()(int i) - { - return i - 1; - } - - int mem1() {return 3;} - int mem2() const {return 4;} - int data_; -}; - -void -test_int_1() -{ - // function - { - std::function<int (int)> r1(f_int_1); - int i = 2; - assert(r1(i) == 3); - } - // function pointer - { - int (*fp)(int) = f_int_1; - std::function<int (int)> r1(fp); - int i = 3; - assert(r1(i) == 4); - } - // functor - { - A_int_1 a0; - std::function<int (int)> r1(a0); - int i = 4; - assert(r1(i) == 3); - } - // member function pointer - { - int (A_int_1::*fp)() = &A_int_1::mem1; - std::function<int (A_int_1)> r1(fp); - A_int_1 a; - assert(r1(a) == 3); - std::function<int (A_int_1*)> r2(fp); - A_int_1* ap = &a; - assert(r2(ap) == 3); - } - // const member function pointer - { - int (A_int_1::*fp)() const = &A_int_1::mem2; - std::function<int (A_int_1)> r1(fp); - A_int_1 a; - assert(r1(a) == 4); - std::function<int (A_int_1*)> r2(fp); - A_int_1* ap = &a; - assert(r2(ap) == 4); - } - // member data pointer - { - int A_int_1::*fp = &A_int_1::data_; - std::function<int& (A_int_1&)> r1(fp); - A_int_1 a; - assert(r1(a) == 5); - r1(a) = 6; - assert(r1(a) == 6); - std::function<int& (A_int_1*)> r2(fp); - A_int_1* ap = &a; - assert(r2(ap) == 6); - r2(ap) = 7; - assert(r2(ap) == 7); - } -} - -// 2 arg, return void - -void f_void_2(int i, int j) -{ - count += i+j; -} - -struct A_void_2 -{ - void operator()(int i, int j) - { - count += i+j; - } - - void mem1(int i) {count += i;} - void mem2(int i) const {count += i;} -}; - -void -test_void_2() -{ - int save_count = count; - // function - { - std::function<void (int, int)> r1(f_void_2); - int i = 2; - int j = 3; - r1(i, j); - assert(count == save_count+5); - save_count = count; - } - // function pointer - { - void (*fp)(int, int) = f_void_2; - std::function<void (int, int)> r1(fp); - int i = 3; - int j = 4; - r1(i, j); - assert(count == save_count+7); - save_count = count; - } - // functor - { - A_void_2 a0; - std::function<void (int, int)> r1(a0); - int i = 4; - int j = 5; - r1(i, j); - assert(count == save_count+9); - save_count = count; - } - // member function pointer - { - void (A_void_2::*fp)(int) = &A_void_2::mem1; - std::function<void (A_void_2, int)> r1(fp); - A_void_2 a; - int i = 3; - r1(a, i); - assert(count == save_count+3); - save_count = count; - std::function<void (A_void_2*, int)> r2(fp); - A_void_2* ap = &a; - r2(ap, i); - assert(count == save_count+3); - save_count = count; - } - // const member function pointer - { - void (A_void_2::*fp)(int) const = &A_void_2::mem2; - std::function<void (A_void_2, int)> r1(fp); - A_void_2 a; - int i = 4; - r1(a, i); - assert(count == save_count+4); - save_count = count; - std::function<void (A_void_2*, int)> r2(fp); - A_void_2* ap = &a; - r2(ap, i); - assert(count == save_count+4); - save_count = count; - } -} - -// 2 arg, return int - -int f_int_2(int i, int j) -{ - return i+j; -} - -struct A_int_2 -{ - int operator()(int i, int j) - { - return i+j; - } - - int mem1(int i) {return i+1;} - int mem2(int i) const {return i+2;} -}; - -void test_int_2() -{ - // function - { - std::function<int (int, int)> r1(f_int_2); - int i = 2; - int j = 3; - assert(r1(i, j) == i+j); - } - // function pointer - { - int (*fp)(int, int) = f_int_2; - std::function<int (int, int)> r1(fp); - int i = 3; - int j = 4; - assert(r1(i, j) == i+j); - } - // functor - { - A_int_2 a0; - std::function<int (int, int)> r1(a0); - int i = 4; - int j = 5; - assert(r1(i, j) == i+j); - } - // member function pointer - { - int(A_int_2::*fp)(int) = &A_int_2::mem1; - std::function<int (A_int_2, int)> r1(fp); - A_int_2 a; - int i = 3; - assert(r1(a, i) == i+1); - std::function<int (A_int_2*, int)> r2(fp); - A_int_2* ap = &a; - assert(r2(ap, i) == i+1); - } - // const member function pointer - { - int (A_int_2::*fp)(int) const = &A_int_2::mem2; - std::function<int (A_int_2, int)> r1(fp); - A_int_2 a; - int i = 4; - assert(r1(a, i) == i+2); - std::function<int (A_int_2*, int)> r2(fp); - A_int_2* ap = &a; - assert(r2(ap, i) == i+2); - } -} - -int main() -{ - test_void_0(); - test_int_0(); - test_void_1(); - test_int_1(); - test_void_2(); - test_int_2(); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp deleted file mode 100644 index cb45b30a9fd4..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> void assign(F&&, const A&); -// This call was removed post-C++14 - -#include <functional> -#include <cassert> - -#include "test_macros.h" -#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 main() -{ -#if TEST_STD_VER <= 14 - { - std::function<int(int)> f; - f.assign(A(), test_allocator<A>()); - assert(A::count == 1); - assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); - } - assert(A::count == 0); -#endif -} 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 deleted file mode 100644 index 214c3f7c5d83..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp +++ /dev/null @@ -1,193 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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...)> - -// void swap(function& other); - -#include <functional> -#include <cassert> - -#include "count_new.hpp" - -class A { - int data_[10]; - -public: - static int count; - - 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() { --count; } - - 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 A::count = 0; - -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)); - { - std::function<int(int)> f1 = A(1); - std::function<int(int)> f2 = A(2); - assert(A::count == 2); - assert(globalMemCounter.checkOutstandingNewEq(2)); - assert(f1.target<A>()->id() == 1); - assert(f2.target<A>()->id() == 2); - f1.swap(f2); - assert(A::count == 2); - assert(globalMemCounter.checkOutstandingNewEq(2)); - assert(f1.target<A>()->id() == 2); - assert(f2.target<A>()->id() == 1); - } - 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); - f1.swap(f2); - assert(A::count == 1); - assert(globalMemCounter.checkOutstandingNewEq(1)); - assert(*f1.target<int (*)(int)>() == g); - assert(f2.target<A>()->id() == 1); - } - 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(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)); - { - 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); - f1.swap(f2); - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); - 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 == 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); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp deleted file mode 100644 index 5bca0968702c..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 <MoveConstructible R, MoveConstructible ... ArgTypes> -// bool operator==(const function<R(ArgTypes...)>&, nullptr_t); -// -// template <MoveConstructible R, MoveConstructible ... ArgTypes> -// bool operator==(nullptr_t, const function<R(ArgTypes...)>&); -// -// template <MoveConstructible R, MoveConstructible ... ArgTypes> -// bool operator!=(const function<R(ArgTypes...)>&, nullptr_t); -// -// template <MoveConstructible R, MoveConstructible ... ArgTypes> -// bool operator!=(nullptr_t, const function<R(ArgTypes...)>&); - -#include <functional> -#include <cassert> - -int g(int) {return 0;} - -int main() -{ - { - std::function<int(int)> f; - assert(f == nullptr); - assert(nullptr == f); - f = g; - assert(f != nullptr); - assert(nullptr != f); - } -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp deleted file mode 100644 index 7a4678ad1cae..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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<typename T> -// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> -// T* -// target(); -// template<typename T> -// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> -// const T* -// target() const; - -#include <functional> -#include <new> -#include <cstdlib> -#include <cassert> - -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() -{ - { - std::function<int(int)> f = A(); - assert(A::count == 1); - assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); - assert(f.target<int>() == nullptr); - } - assert(A::count == 0); - { - std::function<int(int)> f = g; - assert(A::count == 0); - assert(f.target<int(*)(int)>()); - assert(f.target<A>() == 0); - assert(f.target<int>() == nullptr); - } - assert(A::count == 0); - { - const std::function<int(int)> f = A(); - assert(A::count == 1); - assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); - assert(f.target<int>() == nullptr); - } - assert(A::count == 0); - { - const std::function<int(int)> f = g; - assert(A::count == 0); - assert(f.target<int(*)(int)>()); - assert(f.target<A>() == 0); - assert(f.target<int>() == nullptr); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp deleted file mode 100644 index 7605e3bf666e..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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...)> - -// const std::type_info& target_type() const; - -#include <functional> -#include <typeinfo> -#include <cassert> - -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() -{ - { - std::function<int(int)> f = A(); - assert(f.target_type() == typeid(A)); - } - { - std::function<int(int)> f; - assert(f.target_type() == typeid(void)); - } -} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h b/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h deleted file mode 100644 index f1526544bcfe..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -#ifndef FUNCTION_TYPES_H -#define FUNCTION_TYPES_H - - -class FunctionObject -{ - int data_[10]; // dummy variable to prevent small object optimization in - // std::function -public: - static int count; - - FunctionObject() { - ++count; - for (int i = 0; i < 10; ++i) data_[i] = i; - } - - FunctionObject(const FunctionObject&) {++count;} - ~FunctionObject() {--count; ((void)data_); } - - int operator()() const { return 42; } - int operator()(int i) const { return i; } - int operator()(int i, int) const { return i; } - int operator()(int i, int, int) const { return i; } -}; - -int FunctionObject::count = 0; - -class MemFunClass -{ - int data_[10]; // dummy variable to prevent small object optimization in - // std::function -public: - static int count; - - MemFunClass() { - ++count; - for (int i = 0; i < 10; ++i) data_[i] = 0; - } - - MemFunClass(const MemFunClass&) {++count; ((void)data_); } - - ~MemFunClass() {--count;} - - int foo() const { return 42; } - int foo(int i) const { return i; } - int foo(int i, int) const { return i; } - int foo(int i, int, int) const { return i; } -}; - -int MemFunClass::count = 0; - -int FreeFunction() { return 42; } -int FreeFunction(int i) {return i;} -int FreeFunction(int i, int) { return i; } -int FreeFunction(int i, int, int) { return i; } - -#endif // FUNCTION_TYPES_H diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp deleted file mode 100644 index e48b8f986916..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp +++ /dev/null @@ -1,108 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// template<Returnable R, CopyConstructible... ArgTypes> -// class function<R(ArgTypes...)> { -// public: -// typedef R result_type; -// typedef T1 argument_type; // iff sizeof...(ArgTypes) == 1 and -// // the type in ArgTypes is T1 -// typedef T1 first_argument_type; // iff sizeof...(ArgTypes) == 2 and -// // ArgTypes contains T1 and T2 -// typedef T2 second_argument_type; // iff sizeof...(ArgTypes) == 2 and -// // ArgTypes contains T1 and T2 -// ... -// }; - -#include <functional> -#include <type_traits> - - -template <typename T> -class has_argument_type -{ - typedef char yes; - typedef long no; - - template <typename C> static yes check( typename C::argument_type * ); - template <typename C> static no check(...); -public: - enum { value = sizeof(check<T>(0)) == sizeof(yes) }; -}; - -template <typename T> -class has_first_argument_type -{ - typedef char yes; - typedef long no; - - template <typename C> static yes check( typename C::first_argument_type * ); - template <typename C> static no check(...); -public: - enum { value = sizeof(check<T>(0)) == sizeof(yes) }; -}; - - -template <typename T> -class has_second_argument_type -{ - typedef char yes; - typedef long no; - - template <typename C> static yes check( typename C::second_argument_type *); - template <typename C> static no check(...); -public: - enum { value = sizeof(check<T>(0)) == sizeof(yes) }; -}; - -template <class F, class return_type> -void test_nullary_function () -{ - static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); - static_assert((!has_argument_type<F>::value), "" ); - static_assert((!has_first_argument_type<F>::value), "" ); - static_assert((!has_second_argument_type<F>::value), "" ); -} - -template <class F, class return_type, class arg_type> -void test_unary_function () -{ - static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); - static_assert((std::is_same<typename F::argument_type, arg_type>::value), "" ); - static_assert((!has_first_argument_type<F>::value), "" ); - static_assert((!has_second_argument_type<F>::value), "" ); -} - -template <class F, class return_type, class arg_type1, class arg_type2> -void test_binary_function () -{ - static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); - static_assert((std::is_same<typename F::first_argument_type, arg_type1>::value), "" ); - static_assert((std::is_same<typename F::second_argument_type, arg_type2>::value), "" ); - static_assert((!has_argument_type<F>::value), "" ); -} - -template <class F, class return_type> -void test_other_function () -{ - static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); - static_assert((!has_argument_type<F>::value), "" ); - static_assert((!has_first_argument_type<F>::value), "" ); - static_assert((!has_second_argument_type<F>::value), "" ); -} - -int main() -{ - test_nullary_function<std::function<int()>, int>(); - test_unary_function <std::function<double(int)>, double, int>(); - test_binary_function <std::function<double(int, char)>, double, int, char>(); - test_other_function <std::function<double(int, char, double)>, double>(); -} |
