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.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 ++++++++++++ 14 files changed, 936 insertions(+) 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 (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con') 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); + } +} -- cgit v1.3