diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:07:56 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:07:56 +0000 |
| commit | f36202620b428c45a1c8d91743727c9313424fb2 (patch) | |
| tree | 14928d8970ba4890a6370aca4c38fc832d45f21f /test/std/utilities/function.objects/func.wrap/func.wrap.func | |
| parent | 0294ba5648d889e48ffee8ddad25944e258940ae (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func')
3 files changed, 96 insertions, 4 deletions
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 index 9b83ddecb974..1c2be02c6212 100644 --- 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 @@ -92,28 +92,28 @@ int main() { { typedef std::function<int()> Func; Func f = g0; - Func& fr = (f = f); + Func& fr = (f = (Func &)f); assert(&fr == &f); assert(*f.target<int(*)()>() == g0); } { typedef std::function<int(int)> Func; Func f = g; - Func& fr = (f = f); + Func& fr = (f = (Func &)f); assert(&fr == &f); assert(*f.target<int(*)(int)>() == g); } { typedef std::function<int(int, int)> Func; Func f = g2; - Func& fr = (f = f); + Func& fr = (f = (Func &)f); assert(&fr == &f); assert(*f.target<int(*)(int, int)>() == g2); } { typedef std::function<int(int, int, int)> Func; Func f = g3; - Func& fr = (f = f); + Func& fr = (f = (Func &)f); assert(&fr == &f); assert(*f.target<int(*)(int, int, int)>() == g3); } diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp new file mode 100644 index 000000000000..0813c48f322e --- /dev/null +++ b/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/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp new file mode 100644 index 000000000000..eeb181928eaf --- /dev/null +++ b/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>()); +} |
