diff options
Diffstat (limited to 'libcxx/test/std/utilities/function.objects')
2 files changed, 92 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp new file mode 100644 index 00000000000..0813c48f322 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(function &&); + +#include <functional> +#include <cassert> + +#include "test_macros.h" + +struct A +{ + static std::function<void()> global; + static bool cancel; + + ~A() { + DoNotOptimize(cancel); + if (cancel) + global = std::function<void()>(nullptr); + } + void operator()() {} +}; + +std::function<void()> A::global; +bool A::cancel = false; + +int main() +{ + A::global = A(); + assert(A::global.target<A>()); + + // Check that we don't recurse in A::~A(). + A::cancel = true; + A::global = std::function<void()>(nullptr); + assert(!A::global.target<A>()); +} diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp new file mode 100644 index 00000000000..eeb181928ea --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(nullptr_t); + +#include <functional> +#include <cassert> + +#include "test_macros.h" + +struct A +{ + static std::function<void()> global; + static bool cancel; + + ~A() { + DoNotOptimize(cancel); + if (cancel) + global = nullptr; + } + void operator()() {} +}; + +std::function<void()> A::global; +bool A::cancel = false; + +int main() +{ + A::global = A(); + assert(A::global.target<A>()); + + // Check that we don't recurse in A::~A(). + A::cancel = true; + A::global = nullptr; + assert(!A::global.target<A>()); +} |