From 51072bd6bf79ef2bc6a922079bff57c31c1effbc Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 23 Jul 2016 20:47:26 +0000 Subject: Vendor import of libc++ release_39 branch r276489: https://llvm.org/svn/llvm-project/libcxx/branches/release_39@276489 --- .../func.wrap.func.con/alloc_rfunction.pass.cpp | 66 +++++++-- .../func.wrap.func.con/copy.pass.cpp | 118 ---------------- .../func.wrap.func.con/copy_move.pass.cpp | 152 +++++++++++++++++++++ .../func.wrap.func.mod/assign_F_alloc.pass.cpp | 4 + .../func.wrap/func.wrap.func/types.pass.cpp | 2 +- 5 files changed, 209 insertions(+), 133 deletions(-) delete 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_move.pass.cpp (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func') 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 index aa6b743b5236..403d646f4216 100644 --- 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 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // class function @@ -14,8 +16,10 @@ // template function(allocator_arg_t, const A&, function&&); #include +#include #include +#include "test_macros.h" #include "min_allocator.h" #include "count_new.hpp" @@ -46,23 +50,57 @@ public: int A::count = 0; +int g(int) { return 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); + 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); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Test that moving a function constructed from a reference wrapper + // is done without allocating. + DisableAllocationGuard g; + using Ref = std::reference_wrapper; + A a; + Ref aref(a); + std::function f(aref); + assert(A::count == 1); + assert(f.target() == nullptr); + assert(f.target()); + std::function f2(std::allocator_arg, std::allocator{}, + std::move(f)); + assert(A::count == 1); + assert(f2.target() == nullptr); + assert(f2.target()); + assert(f.target()); // f is unchanged because the target is small + } + { + // Test that moving a function constructed from a function pointer + // is done without allocating + DisableAllocationGuard guard; + using Ptr = int(*)(int); + Ptr p = g; + std::function f(p); + assert(f.target() == nullptr); + assert(f.target()); + std::function f2(std::allocator_arg, std::allocator(), + std::move(f)); + assert(f2.target() == nullptr); + assert(f2.target()); + assert(f.target()); // f is unchanged because the target is small } -#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 deleted file mode 100644 index f603da9dd131..000000000000 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp +++ /dev/null @@ -1,118 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// 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_move.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp new file mode 100644 index 000000000000..387b371a9331 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp @@ -0,0 +1,152 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +#include "test_macros.h" +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function 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); + } +#if TEST_STD_VER >= 11 + assert(globalMemCounter.checkOutstandingNewEq(0)); + { // Test rvalue references + 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); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Test that moving a function constructed from a reference wrapper + // is done without allocating. + DisableAllocationGuard g; + using Ref = std::reference_wrapper; + A a; + Ref aref(a); + std::function f(aref); + assert(A::count == 1); + assert(f.target() == nullptr); + assert(f.target()); + std::function f2(std::move(f)); + assert(A::count == 1); + assert(f2.target() == nullptr); + assert(f2.target()); + assert(f.target()); // f is unchanged because the target is small + } + { + // Test that moving a function constructed from a function pointer + // is done without allocating + DisableAllocationGuard guard; + using Ptr = int(*)(int); + Ptr p = g; + std::function f(p); + assert(f.target() == nullptr); + assert(f.target()); + std::function f2(std::move(f)); + assert(f2.target() == nullptr); + assert(f2.target()); + assert(f.target()); // f is unchanged because the target is small + } +#endif // TEST_STD_VER >= 11 +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.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 index e9ecfa5539ce..cb45b30a9fd4 100644 --- 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 @@ -12,10 +12,12 @@ // class function // template void assign(F&&, const A&); +// This call was removed post-C++14 #include #include +#include "test_macros.h" #include "test_allocator.h" class A @@ -49,6 +51,7 @@ int A::count = 0; int main() { +#if TEST_STD_VER <= 14 { std::function f; f.assign(A(), test_allocator()); @@ -57,4 +60,5 @@ int main() assert(f.target() == 0); } assert(A::count == 0); +#endif } 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 index eb4eac65cd2c..e48b8f986916 100644 --- 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 @@ -14,7 +14,7 @@ // public: // typedef R result_type; // typedef T1 argument_type; // iff sizeof...(ArgTypes) == 1 and -// // the type in ArgTypes is T1 +// // 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 -- cgit v1.2.3