From 5a83710e371fe68a06e6e3876c6a2c8b820a8976 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 20 Dec 2014 01:40:03 +0000 Subject: Move test into test/std subdirectory. llvm-svn: 224658 --- .../func.wrap.func.targ/target.pass.cpp | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp (limited to 'libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp') diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp new file mode 100644 index 00000000000..53476a27473 --- /dev/null +++ b/libcxx/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); +} -- cgit v1.2.3