From 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 6 Sep 2015 18:46:46 +0000 Subject: Import libc++ 3.7.0 release (r246257). --- .../func.wrap.badcall/bad_function_call.pass.cpp | 26 ++ .../bad_function_call_ctor.pass.cpp | 20 ++ .../func.wrap.func.alg/swap.pass.cpp | 123 ++++++++ .../func.wrap.func.cap/operator_bool.pass.cpp | 29 ++ .../func.wrap.func/func.wrap.func.con/F.pass.cpp | 90 ++++++ .../func.wrap.func.con/F_assign.pass.cpp | 98 ++++++ .../func.wrap.func.con/F_incomplete.pass.cpp | 29 ++ .../func.wrap.func.con/alloc.pass.cpp | 27 ++ .../func.wrap.func.con/alloc_F.pass.cpp | 106 +++++++ .../func.wrap.func.con/alloc_function.pass.cpp | 124 ++++++++ .../func.wrap.func.con/alloc_nullptr.pass.cpp | 25 ++ .../func.wrap.func.con/alloc_rfunction.pass.cpp | 68 +++++ .../func.wrap.func.con/copy.pass.cpp | 118 ++++++++ .../func.wrap.func.con/copy_assign.pass.cpp | 109 +++++++ .../func.wrap.func.con/default.pass.cpp | 23 ++ .../func.wrap.func.con/no-variadics.pass.cpp | 24 ++ .../func.wrap.func.con/nullptr_t.pass.cpp | 23 ++ .../func.wrap.func.con/nullptr_t_assign.pass.cpp | 72 +++++ .../func.wrap.func.inv/invoke.fail.cpp | 46 +++ .../func.wrap.func.inv/invoke.pass.cpp | 335 +++++++++++++++++++++ .../func.wrap.func.inv/invoke_int_0.pass.cpp | 58 ++++ .../invoke_no_variadics.pass.cpp | 60 ++++ .../func.wrap.func.inv/invoke_void_0.pass.cpp | 67 +++++ .../func.wrap.func.mod/assign_F_alloc.pass.cpp | 60 ++++ .../func.wrap.func.mod/swap.pass.cpp | 120 ++++++++ .../func.wrap.func.nullptr/operator_==.pass.cpp | 41 +++ .../func.wrap.func.targ/target.pass.cpp | 89 ++++++ .../func.wrap.func.targ/target_type.pass.cpp | 61 ++++ .../func.wrap/func.wrap.func/function_types.h | 57 ++++ .../func.wrap/func.wrap.func/types.pass.cpp | 108 +++++++ .../func.wrap/nothing_to_do.pass.cpp | 12 + 31 files changed, 2248 insertions(+) create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h create mode 100644 test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp create mode 100644 test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp (limited to 'test/std/utilities/function.objects/func.wrap') diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp new file mode 100644 index 000000000000..357a3b48eae2 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// class bad_function_call +// : public exception +// { +// public: +// // 20.7.16.1.1, constructor: +// bad_function_call(); +// }; + +#include +#include + +int main() +{ + static_assert((std::is_base_of::value), ""); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp new file mode 100644 index 000000000000..f5ab9487532f --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// bad_function_call(); + +#include +#include + +int main() +{ + std::bad_function_call ex; +} 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 new file mode 100644 index 000000000000..58192c928d58 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template +// void swap(function&, function&); + + +#include +#include +#include + +#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 f1 = A(1); + std::function f2 = A(2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target()->id() == 1); + assert(f2.target()->id() == 2); + swap(f1, f2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target()->id() == 2); + assert(f2.target()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = A(1); + std::function f2 = g; + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target()->id() == 1); + assert(*f2.target() == g); + swap(f1, f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target() == g); + assert(f2.target()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = g; + std::function f2 = A(1); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target() == g); + assert(f2.target()->id() == 1); + swap(f1, f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target()->id() == 1); + assert(*f2.target() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = g; + std::function f2 = h; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target() == g); + assert(*f2.target() == h); + swap(f1, f2); + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target() == h); + assert(*f2.target() == 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 new file mode 100644 index 000000000000..829763f79d82 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// explicit operator bool() const + +#include +#include + +int g(int) {return 0;} + +int main() +{ + { + std::function 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 new file mode 100644 index 000000000000..cd86e4cbf8eb --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// function(nullptr_t); + +#include +#include + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target()); + assert(f.target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = (int (*)(int))0; + assert(!f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + assert(f.target() == 0); + } + { + std::function f = &A::foo; + assert(f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() != 0); + } + { + std::function f(&g); + assert(f); + assert(f.target() != 0); + f(1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp new file mode 100644 index 000000000000..11716e7946b0 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template +// requires CopyConstructible && Callable +// && Convertible::result_type +// operator=(F f); + +#include +#include + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f; + f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f; + f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target()); + assert(f.target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f; + f = (int (*)(int))0; + assert(!f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + assert(f.target() == 0); + } + { + std::function f; + f = &A::foo; + assert(f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() != 0); + } + { + std::function f; + f = &g; + assert(f); + assert(f.target() != 0); + f(1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp new file mode 100644 index 000000000000..c8f4178a26bd --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(F); + +// Allow incomplete argument types in the __is_callable check + +#include + +struct X{ + typedef std::function callback_type; + virtual ~X() {} +private: + callback_type _cb; +}; + +int main() +{ +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp new file mode 100644 index 000000000000..f97e34d3f2cb --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(allocator_arg_t, const A&); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::function f(std::allocator_arg, bare_allocator()); + assert(!f); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp new file mode 100644 index 000000000000..352ecfc602be --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(allocator_arg_t, const A&, F); + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "count_new.hpp" +#include "../function_types.h" + +class DummyClass {}; + +template +void test_FunctionObject(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + FunctionObject target; + assert(FunctionObject::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function f2(std::allocator_arg, alloc, target); + assert(FunctionObject::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.template target()); + assert(f2.template target() == 0); + assert(f2.template target() == 0); + } + assert(FunctionObject::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + + +template +void test_FreeFunction(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + FuncType* target = &FreeFunction; + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function f2(std::allocator_arg, alloc, target); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target()); + assert(*f2.template target() == target); + assert(f2.template target() == 0); + assert(f2.template target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template +void test_MemFunClass(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + TargetType target = &MemFunClass::foo; + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function f2(std::allocator_arg, alloc, target); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target()); + assert(*f2.template target() == target); + assert(f2.template target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template +void test_for_alloc(Alloc& alloc) { + test_FunctionObject(alloc); + test_FunctionObject(alloc); + test_FunctionObject(alloc); + test_FunctionObject(alloc); + + test_FreeFunction(alloc); + test_FreeFunction(alloc); + test_FreeFunction(alloc); + test_FreeFunction(alloc); + + test_MemFunClass(alloc); + test_MemFunClass(alloc); + test_MemFunClass(alloc); +} + +int main() +{ + { + bare_allocator bare_alloc; + test_for_alloc(bare_alloc); + } + { + non_default_test_allocator non_default_alloc(42); + test_for_alloc(non_default_alloc); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp new file mode 100644 index 000000000000..371eb98de1a9 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(allocator_arg_t, const A&, const function&); + + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "count_new.hpp" +#include "../function_types.h" + +class DummyClass {}; + +template +void test_FunctionObject(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from FunctionObject. + std::function f = FunctionObject(); + assert(FunctionObject::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.template target()); + assert(f.template target() == 0); + assert(f.template target() == 0); + // Copy function with allocator + std::function f2(std::allocator_arg, alloc, f); + assert(FunctionObject::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.template target()); + assert(f2.template target() == 0); + assert(f2.template target() == 0); + } + assert(FunctionObject::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template +void test_FreeFunction(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from function pointer. + FuncType* target = &FreeFunction; + std::function f = target; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.template target()); + assert(*f.template target() == target); + assert(f.template target() == 0); + // Copy function with allocator + std::function f2(std::allocator_arg, alloc, f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target()); + assert(*f2.template target() == target); + assert(f2.template target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template +void test_MemFunClass(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from function pointer. + TargetType target = &MemFunClass::foo; + std::function f = target; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.template target()); + assert(*f.template target() == target); + assert(f.template target() == 0); + // Copy function with allocator + std::function f2(std::allocator_arg, alloc, f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target()); + assert(*f2.template target() == target); + assert(f2.template target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template +void test_for_alloc(Alloc& alloc) +{ + // Large FunctionObject -- Allocation should occur + test_FunctionObject(alloc); + test_FunctionObject(alloc); + test_FunctionObject(alloc); + test_FunctionObject(alloc); + // Free function -- No allocation should occur + test_FreeFunction(alloc); + test_FreeFunction(alloc); + test_FreeFunction(alloc); + test_FreeFunction(alloc); + // Member function -- No allocation should occur. + test_MemFunClass(alloc); + test_MemFunClass(alloc); + test_MemFunClass(alloc); +} + +int main() +{ + { + bare_allocator alloc; + test_for_alloc(alloc); + } + { + non_default_test_allocator alloc(42); + test_for_alloc(alloc); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp new file mode 100644 index 000000000000..2350f92f0f89 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(allocator_arg_t, const A&, nullptr_t); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + std::function f(std::allocator_arg, bare_allocator(), nullptr); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp new file mode 100644 index 000000000000..aa6b743b5236 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(allocator_arg_t, const A&, function&&); + +#include +#include + +#include "min_allocator.h" +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + std::function f2(std::allocator_arg, bare_allocator(), std::move(f)); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target()); + assert(f2.target() == 0); + assert(f.target() == 0); + assert(f.target() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp new file mode 100644 index 000000000000..f603da9dd131 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// function(const function& f); + +#include +#include +#include + +#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 f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + std::function f2 = f; + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.target()); + assert(f2.target() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target()); + assert(f.target() == 0); + std::function f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target()); + assert(f2.target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + assert(f.target() == 0); + std::function f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target() == 0); + assert(f2.target() == 0); + } + { + std::function f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + assert(f.target() == 0); + assert(!f); + std::function g = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(g.target() == 0); + assert(g.target() == 0); + assert(!g); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + std::function f2 = std::move(f); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target()); + assert(f2.target() == 0); + assert(f.target() == 0); + assert(f.target() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp new file mode 100644 index 000000000000..c91eaa2d5674 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// function& operator=(const function& f); + +#include +#include + +#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 f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + std::function f2; + f2 = f; + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.target()); + assert(f2.target() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target()); + assert(f.target() == 0); + std::function f2; + f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target()); + assert(f2.target() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + assert(f.target() == 0); + std::function f2; + f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target() == 0); + assert(f2.target() == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + assert(f.target() == 0); + std::function f2; + f2 = std::move(f); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target()); + assert(f2.target() == 0); + assert(f.target() == 0); + assert(f.target() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp new file mode 100644 index 000000000000..83d61b6b2d89 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// explicit function(); + +#include +#include + +int main() +{ + std::function f; + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp new file mode 100644 index 000000000000..7099c45fab81 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template function(F); + +#define _LIBCPP_HAS_NO_VARIADICS +#include +#include + +int main() +{ + std::function f(static_cast(0)); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp new file mode 100644 index 000000000000..f0d6402d185e --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// function(nullptr_t); + +#include +#include + +int main() +{ + std::function f(nullptr); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp new file mode 100644 index 000000000000..9b2482fb9d54 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// function& operator=(nullptr_t); + +#include +#include + +#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 f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target()); + f = nullptr; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + } + { + std::function f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target()); + assert(f.target() == 0); + f = nullptr; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target() == 0); + } +} 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 new file mode 100644 index 000000000000..6dcd2857452c --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// R operator()(ArgTypes... args) const + +#include +#include + +// 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 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 new file mode 100644 index 000000000000..31b80c3323c1 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp @@ -0,0 +1,335 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// R operator()(ArgTypes... args) const + +#include +#include + +int count = 0; + +// 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 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 r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::function 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 r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::function 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 r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + std::function 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 r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::function r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::function r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::function r1(fp); + A_int_1 a; + assert(r1(a) == 3); + std::function 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 r1(fp); + A_int_1 a; + assert(r1(a) == 4); + std::function 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 r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + std::function 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 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 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 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 r1(fp); + A_void_2 a; + int i = 3; + r1(a, i); + assert(count == save_count+3); + save_count = count; + std::function 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 r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + std::function 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 +testint_2() +{ + // function + { + std::function 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 r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::function 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 r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + std::function 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 r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + std::function r2(fp); + A_int_2* ap = &a; + assert(r2(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp new file mode 100644 index 000000000000..67b4ec22da8c --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// R operator()(ArgTypes... args) const + +#include +#include + +// 0 args, return int + +int count = 0; + +int f_int_0() +{ + return 3; +} + +struct A_int_0 +{ + int operator()() {return 4;} +}; + +void +test_int_0() +{ + // function + { + std::function r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::function r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::function r1(a0); + assert(r1() == 4); + } +} + +int main() +{ + test_int_0(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp new file mode 100644 index 000000000000..c0a14fd96fcb --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// Test that we properly return both values and void for all non-variadic +// overloads of function::operator()(...) + +#define _LIBCPP_HAS_NO_VARIADICS +#include +#include + +int foo0() { return 42; } +int foo1(int) { return 42; } +int foo2(int, int) { return 42; } +int foo3(int, int, int) { return 42; } + +int main() +{ + { + std::function f(&foo0); + assert(f() == 42); + } + { + std::function f(&foo1); + assert(f(1) == 42); + } + { + std::function f(&foo2); + assert(f(1, 1) == 42); + } + { + std::function f(&foo3); + assert(f(1, 1, 1) == 42); + } + { + std::function f(&foo0); + f(); + } + { + std::function f(&foo1); + f(1); + } + { + std::function f(&foo2); + f(1, 1); + } + { + std::function f(&foo3); + f(1, 1, 1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp new file mode 100644 index 000000000000..a820cb1b8f38 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// R operator()(ArgTypes... args) const + +#include +#include +#include +#include + +// 0 args, return void + +int count = 0; + +void f_void_0() +{ + ++count; +} + +struct A_void_0 +{ + void operator()() {++count;} +}; + +void +test_void_0() +{ + int save_count = count; + // function + { + std::function r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::function r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::function r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} 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 new file mode 100644 index 000000000000..e9ecfa5539ce --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template void assign(F&&, const A&); + +#include +#include + +#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() +{ + { + std::function f; + f.assign(A(), test_allocator()); + assert(A::count == 1); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); +} 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 new file mode 100644 index 000000000000..f94e689b2a6b --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// void swap(function& other); + +#include +#include + +#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 f1 = A(1); + std::function f2 = A(2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target()->id() == 1); + assert(f2.target()->id() == 2); + f1.swap(f2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target()->id() == 2); + assert(f2.target()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = A(1); + std::function f2 = g; + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target()->id() == 1); + assert(*f2.target() == g); + f1.swap(f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target() == g); + assert(f2.target()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = g; + std::function f2 = A(1); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target() == g); + assert(f2.target()->id() == 1); + f1.swap(f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target()->id() == 1); + assert(*f2.target() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function f1 = g; + std::function f2 = h; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target() == g); + assert(*f2.target() == h); + f1.swap(f2); + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target() == h); + assert(*f2.target() == 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.nullptr/operator_==.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp new file mode 100644 index 000000000000..5bca0968702c --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template +// bool operator==(const function&, nullptr_t); +// +// template +// bool operator==(nullptr_t, const function&); +// +// template +// bool operator!=(const function&, nullptr_t); +// +// template +// bool operator!=(nullptr_t, const function&); + +#include +#include + +int g(int) {return 0;} + +int main() +{ + { + std::function 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 new file mode 100644 index 000000000000..53476a274735 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// template +// requires Callable && Convertible::result_type, R> +// T* +// target(); +// template +// requires Callable && Convertible::result_type, R> +// const T* +// target() const; + +#include +#include +#include +#include + +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 f = A(); + assert(A::count == 1); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); + { + std::function f = g; + assert(A::count == 0); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); + { + const std::function f = A(); + assert(A::count == 1); + assert(f.target()); + assert(f.target() == 0); + } + assert(A::count == 0); + { + const std::function f = g; + assert(A::count == 0); + assert(f.target()); + assert(f.target() == 0); + } + 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 new file mode 100644 index 000000000000..7605e3bf666e --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// class function + +// const std::type_info& target_type() const; + +#include +#include +#include + +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 f = A(); + assert(f.target_type() == typeid(A)); + } + { + std::function 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 new file mode 100644 index 000000000000..55eb80f43ffe --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h @@ -0,0 +1,57 @@ +#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 new file mode 100644 index 000000000000..eb4eac65cd2c --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class function { +// 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 +#include + + +template +class has_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::argument_type * ); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + +template +class has_first_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::first_argument_type * ); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + + +template +class has_second_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::second_argument_type *); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + +template +void test_nullary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + +template +void test_unary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + +template +void test_binary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); +} + +template +void test_other_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + +int main() +{ + test_nullary_function, int>(); + test_unary_function , double, int>(); + test_binary_function , double, int, char>(); + test_other_function , double>(); +} diff --git a/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp b/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} -- cgit v1.3