summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/thread/futures/futures.task/futures.task.members
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-06-01 21:05:53 +0000
committerEric Fiselier <eric@efcs.ca>2016-06-01 21:05:53 +0000
commiteb5cfb02d6a3c757940d8ad3f31a4286535a32ad (patch)
tree61c64393998a42a844b8ee101abb75128f377bd7 /libcxx/test/std/thread/futures/futures.task/futures.task.members
parentf807dce6da05ef506b6a21b611f855f9eb209692 (diff)
downloadbcm5719-llvm-eb5cfb02d6a3c757940d8ad3f31a4286535a32ad.tar.gz
bcm5719-llvm-eb5cfb02d6a3c757940d8ad3f31a4286535a32ad.zip
Cleanup non-standard tests as reported by STL@microsoft.com. NFC.
This patch addresses the following issues in the test suite: 1. Move "std::bad_array_length" test from std/ to libcxx/ test directory since the feature is not a part of the standard. 2. Rename "futures.tas" test directory to "futures.task" since that is the correct stable name. 3. Move tests for "packaged_task<T>::result_type" from std/ to libcxx/ test directory since the typedef is a libc++ extension. llvm-svn: 271430
Diffstat (limited to 'libcxx/test/std/thread/futures/futures.task/futures.task.members')
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_copy.fail.cpp27
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_move.pass.cpp51
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor1.fail.cpp33
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp34
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_copy.fail.cpp28
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_default.pass.cpp28
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func.pass.cpp80
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp125
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_move.pass.cpp49
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp64
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp66
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp108
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp109
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp62
-rw-r--r--libcxx/test/std/thread/futures/futures.task/futures.task.members/swap.pass.cpp51
15 files changed, 915 insertions, 0 deletions
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_copy.fail.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_copy.fail.cpp
new file mode 100644
index 00000000000..9449e149027
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_copy.fail.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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// packaged_task& operator=(packaged_task&) = delete;
+
+#include <future>
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p0, p;
+ p = p0; // expected-error {{overload resolution selected deleted operator '='}}
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_move.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_move.pass.cpp
new file mode 100644
index 00000000000..3f11d670bed
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_move.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// packaged_task& operator=(packaged_task&& other);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p0(A(5));
+ std::packaged_task<double(int, char)> p;
+ p = std::move(p0);
+ assert(!p0.valid());
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p0;
+ std::packaged_task<double(int, char)> p;
+ p = std::move(p0);
+ assert(!p0.valid());
+ assert(!p.valid());
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor1.fail.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor1.fail.cpp
new file mode 100644
index 00000000000..6d7d734bd5e
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor1.fail.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+// template <class F>
+// packaged_task(F&& f);
+// These constructors shall not participate in overload resolution if
+// decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
+
+#include <future>
+#include <cassert>
+
+struct A {};
+typedef std::packaged_task<A(int, char)> PT;
+typedef volatile std::packaged_task<A(int, char)> VPT;
+
+
+int main()
+{
+ PT p { VPT{} }; // expected-error {{no matching constructor for initialization of 'PT' (aka 'packaged_task<A (int, char)>')}}
+ // expected-note@future:* 1 {{candidate template ignored: disabled by 'enable_if'}}
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp
new file mode 100644
index 00000000000..984dcdc80b3
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+// template <class F, class Allocator>
+// packaged_task(allocator_arg_t, const Allocator& a, F&& f);
+// These constructors shall not participate in overload resolution if
+// decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
+
+#include <future>
+#include <cassert>
+
+#include "test_allocator.h"
+
+struct A {};
+typedef std::packaged_task<A(int, char)> PT;
+typedef volatile std::packaged_task<A(int, char)> VPT;
+
+int main()
+{
+ PT p { std::allocator_arg_t{}, test_allocator<A>{}, VPT {}}; // expected-error {{no matching constructor for initialization of 'PT' (aka 'packaged_task<A (int, char)>')}}
+ // expected-note@future:* 1 {{candidate template ignored: disabled by 'enable_if'}}
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_copy.fail.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_copy.fail.cpp
new file mode 100644
index 00000000000..ff07db9a2e6
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_copy.fail.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// packaged_task(packaged_task&) = delete;
+
+#include <future>
+
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p0;
+ std::packaged_task<double(int, char)> p(p0); // expected-error {{call to deleted constructor of 'std::packaged_task<double (int, char)>'}}
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_default.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_default.pass.cpp
new file mode 100644
index 00000000000..ed147d74895
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_default.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// packaged_task();
+
+#include <future>
+#include <cassert>
+
+struct A {};
+
+int main()
+{
+ std::packaged_task<A(int, char)> p;
+ assert(!p.valid());
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func.pass.cpp
new file mode 100644
index 00000000000..14ac7614bb8
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// template <class F>
+// explicit packaged_task(F&& f);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ static int n_moves;
+ static int n_copies;
+
+ explicit A(long i) : data_(i) {}
+ A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
+ A(const A& a) : data_(a.data_) {++n_copies;}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int A::n_moves = 0;
+int A::n_copies = 0;
+
+int func(int i) { return i; }
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies == 0);
+ assert(A::n_moves > 0);
+ }
+ A::n_copies = 0;
+ A::n_copies = 0;
+ {
+ A a(5);
+ std::packaged_task<double(int, char)> p(a);
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies > 0);
+ assert(A::n_moves > 0);
+ }
+ {
+ std::packaged_task<int(int)> p(&func);
+ assert(p.valid());
+ std::future<int> f = p.get_future();
+ p(4);
+ assert(f.get() == 4);
+ }
+ {
+ std::packaged_task<int(int)> p(func);
+ assert(p.valid());
+ std::future<int> f = p.get_future();
+ p(4);
+ assert(f.get() == 4);
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp
new file mode 100644
index 00000000000..39784876b8c
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp
@@ -0,0 +1,125 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// template <class F, class Allocator>
+// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
+
+#include <future>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_allocator.h"
+
+class A
+{
+ long data_;
+
+public:
+ static int n_moves;
+ static int n_copies;
+
+ explicit A(long i) : data_(i) {}
+ A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
+ A(const A& a) : data_(a.data_) {++n_copies;}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int A::n_moves = 0;
+int A::n_copies = 0;
+
+int func(int i) { return i; }
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(std::allocator_arg,
+ test_allocator<A>(), A(5));
+ assert(test_alloc_base::alloc_count > 0);
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies == 0);
+ assert(A::n_moves > 0);
+ }
+ assert(test_alloc_base::alloc_count == 0);
+ A::n_copies = 0;
+ A::n_moves = 0;
+ {
+ A a(5);
+ std::packaged_task<double(int, char)> p(std::allocator_arg,
+ test_allocator<A>(), a);
+ assert(test_alloc_base::alloc_count > 0);
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies > 0);
+ assert(A::n_moves > 0);
+ }
+ assert(test_alloc_base::alloc_count == 0);
+ A::n_copies = 0;
+ A::n_moves = 0;
+ {
+ A a(5);
+ std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(), &func);
+ assert(test_alloc_base::alloc_count > 0);
+ assert(p.valid());
+ std::future<int> f = p.get_future();
+ p(4);
+ assert(f.get() == 4);
+ }
+ assert(test_alloc_base::alloc_count == 0);
+ A::n_copies = 0;
+ A::n_moves = 0;
+ {
+ A a(5);
+ std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(), func);
+ assert(test_alloc_base::alloc_count > 0);
+ assert(p.valid());
+ std::future<int> f = p.get_future();
+ p(4);
+ assert(f.get() == 4);
+ }
+ assert(test_alloc_base::alloc_count == 0);
+ A::n_copies = 0;
+ A::n_moves = 0;
+ {
+ std::packaged_task<double(int, char)> p(std::allocator_arg,
+ bare_allocator<void>(), A(5));
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies == 0);
+ assert(A::n_moves > 0);
+ }
+ A::n_copies = 0;
+ A::n_moves = 0;
+ {
+ std::packaged_task<double(int, char)> p(std::allocator_arg,
+ min_allocator<void>(), A(5));
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ assert(A::n_copies == 0);
+ assert(A::n_moves > 0);
+ }
+ A::n_copies = 0;
+ A::n_moves = 0;
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_move.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_move.pass.cpp
new file mode 100644
index 00000000000..d9951dca585
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_move.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// packaged_task(packaged_task&& other);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p0(A(5));
+ std::packaged_task<double(int, char)> p = std::move(p0);
+ assert(!p0.valid());
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p0;
+ std::packaged_task<double(int, char)> p = std::move(p0);
+ assert(!p0.valid());
+ assert(!p.valid());
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
new file mode 100644
index 00000000000..7fafd100564
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: libcpp-no-exceptions
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// ~packaged_task();
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+void func(std::packaged_task<double(int, char)> p)
+{
+}
+
+void func2(std::packaged_task<double(int, char)> p)
+{
+ p(3, 'a');
+}
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func, std::move(p)).detach();
+ try
+ {
+ double i = f.get();
+ assert(false);
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::broken_promise));
+ }
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func2, std::move(p)).detach();
+ assert(f.get() == 105.0);
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp
new file mode 100644
index 00000000000..c8e5d6efd6b
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: libcpp-no-exceptions
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// future<R> get_future();
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ try
+ {
+ f = p.get_future();
+ assert(false);
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::future_already_retrieved));
+ }
+ }
+ {
+ std::packaged_task<double(int, char)> p;
+ try
+ {
+ std::future<double> f = p.get_future();
+ assert(false);
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::no_state));
+ }
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
new file mode 100644
index 00000000000..54ac6445824
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
@@ -0,0 +1,108 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: libcpp-no-exceptions
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// void make_ready_at_thread_exit(ArgTypes... args);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const
+ {
+ if (j == 'z')
+ throw A(6);
+ return data_ + i + j;
+ }
+};
+
+void func0(std::packaged_task<double(int, char)> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.make_ready_at_thread_exit(3, 'a');
+}
+
+void func1(std::packaged_task<double(int, char)> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p.make_ready_at_thread_exit(3, 'z');
+}
+
+void func2(std::packaged_task<double(int, char)> p)
+{
+ p.make_ready_at_thread_exit(3, 'a');
+ try
+ {
+ p.make_ready_at_thread_exit(3, 'c');
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
+ }
+}
+
+void func3(std::packaged_task<double(int, char)> p)
+{
+ try
+ {
+ p.make_ready_at_thread_exit(3, 'a');
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::no_state));
+ }
+}
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func0, std::move(p)).detach();
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ try
+ {
+ f.get();
+ assert(false);
+ }
+ catch (const A& e)
+ {
+ assert(e(3, 'a') == 106);
+ }
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func2, std::move(p)).detach();
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p;
+ std::thread t(func3, std::move(p));
+ t.join();
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
new file mode 100644
index 00000000000..9ad1509517f
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.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.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: libcpp-no-exceptions
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// void operator()(ArgTypes... args);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const
+ {
+ if (j == 'z')
+ throw A(6);
+ return data_ + i + j;
+ }
+};
+
+void func0(std::packaged_task<double(int, char)> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p(3, 'a');
+}
+
+void func1(std::packaged_task<double(int, char)> p)
+{
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ p(3, 'z');
+}
+
+void func2(std::packaged_task<double(int, char)> p)
+{
+ p(3, 'a');
+ try
+ {
+ p(3, 'c');
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
+ }
+}
+
+void func3(std::packaged_task<double(int, char)> p)
+{
+ try
+ {
+ p(3, 'a');
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::no_state));
+ }
+}
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func0, std::move(p)).detach();
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ try
+ {
+ f.get();
+ assert(false);
+ }
+ catch (const A& e)
+ {
+ assert(e(3, 'a') == 106);
+ }
+ }
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ std::thread t(func2, std::move(p));
+ assert(f.get() == 105.0);
+ t.join();
+ }
+ {
+ std::packaged_task<double(int, char)> p;
+ std::thread t(func3, std::move(p));
+ t.join();
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
new file mode 100644
index 00000000000..02a567500ee
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// XFAIL: libcpp-no-exceptions
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// void reset();
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const
+ {
+ if (j == 'z')
+ throw A(6);
+ return data_ + i + j;
+ }
+};
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p(A(5));
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ p.reset();
+ p(4, 'a');
+ f = p.get_future();
+ assert(f.get() == 106.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p;
+ try
+ {
+ p.reset();
+ assert(false);
+ }
+ catch (const std::future_error& e)
+ {
+ assert(e.code() == make_error_code(std::future_errc::no_state));
+ }
+ }
+}
diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/swap.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/swap.pass.cpp
new file mode 100644
index 00000000000..eb0091c8e81
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/swap.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <future>
+
+// class packaged_task<R(ArgTypes...)>
+
+// void swap(packaged_task& other);
+
+#include <future>
+#include <cassert>
+
+class A
+{
+ long data_;
+
+public:
+ explicit A(long i) : data_(i) {}
+
+ long operator()(long i, long j) const {return data_ + i + j;}
+};
+
+int main()
+{
+ {
+ std::packaged_task<double(int, char)> p0(A(5));
+ std::packaged_task<double(int, char)> p;
+ p.swap(p0);
+ assert(!p0.valid());
+ assert(p.valid());
+ std::future<double> f = p.get_future();
+ p(3, 'a');
+ assert(f.get() == 105.0);
+ }
+ {
+ std::packaged_task<double(int, char)> p0;
+ std::packaged_task<double(int, char)> p;
+ p.swap(p0);
+ assert(!p0.valid());
+ assert(!p.valid());
+ }
+}
OpenPOWER on IntegriCloud