aboutsummaryrefslogtreecommitdiff
path: root/test/std/thread/futures/futures.unique_future
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/futures/futures.unique_future')
-rw-r--r--test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp59
-rw-r--r--test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp51
-rw-r--r--test/std/thread/futures/futures.unique_future/dtor.pass.cpp30
-rw-r--r--test/std/thread/futures/futures.unique_future/get.pass.cpp2
-rw-r--r--test/std/thread/futures/futures.unique_future/share.pass.cpp1
-rw-r--r--test/std/thread/futures/futures.unique_future/wait.pass.cpp1
-rw-r--r--test/std/thread/futures/futures.unique_future/wait_for.pass.cpp1
-rw-r--r--test/std/thread/futures/futures.unique_future/wait_until.pass.cpp259
8 files changed, 185 insertions, 219 deletions
diff --git a/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp b/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp
index ebdcbf98d996..781c9c9d6199 100644
--- a/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp
+++ b/test/std/thread/futures/futures.unique_future/copy_assign.fail.cpp
@@ -14,61 +14,36 @@
// future& operator=(const future&) = delete;
#include <future>
-#include <cassert>
+
+#include "test_macros.h"
int main()
{
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#if TEST_STD_VER >= 11
{
- typedef int T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<int> f0, f;
+ f = f0; // expected-error {{overload resolution selected deleted operator '='}}
}
{
- typedef int T;
- std::future<T> f0;
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<int &> f0, f;
+ f = f0; // expected-error {{overload resolution selected deleted operator '='}}
}
{
- typedef int& T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<void> f0, f;
+ f = f0; // expected-error {{overload resolution selected deleted operator '='}}
}
+#else
{
- typedef int& T;
- std::future<T> f0;
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<int> f0, f;
+ f = f0; // expected-error {{'operator=' is a private member of 'std::__1::future<int>'}}
}
{
- typedef void T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<int &> f0, f;
+ f = f0; // expected-error {{'operator=' is a private member of 'std::__1::future<int &>'}}
}
{
- typedef void T;
- std::future<T> f0;
- std::future<T> f;
- f = f0;
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<void> f0, f;
+ f = f0; // expected-error {{'operator=' is a private member of 'std::__1::future<void>'}}
}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#endif
}
diff --git a/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp b/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp
index 8d43294edc26..0d7b5f5074d3 100644
--- a/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp
+++ b/test/std/thread/futures/futures.unique_future/copy_ctor.fail.cpp
@@ -14,53 +14,36 @@
// future(const future&) = delete;
#include <future>
-#include <cassert>
+
+#include "test_macros.h"
int main()
{
+#if TEST_STD_VER >= 11
{
- typedef int T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<int> f0;
+ std::future<int> f = f0; // expected-error {{call to deleted constructor of 'std::future<int>'}}
}
{
- typedef int T;
- std::future<T> f0;
- std::future<T> f = f0;
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<int &> f0;
+ std::future<int &> f = f0; // expected-error {{call to deleted constructor of 'std::future<int &>'}}
}
{
- typedef int& T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<void> f0;
+ std::future<void> f = f0; // expected-error {{call to deleted constructor of 'std::future<void>'}}
}
+#else
{
- typedef int& T;
- std::future<T> f0;
- std::future<T> f = std::move(f0);
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<int> f0;
+ std::future<int> f = f0; // expected-error {{calling a private constructor of class 'std::__1::future<int>'}}
}
{
- typedef void T;
- std::promise<T> p;
- std::future<T> f0 = p.get_future();
- std::future<T> f = f0;
- assert(!f0.valid());
- assert(f.valid());
+ std::future<int &> f0;
+ std::future<int &> f = f0; // expected-error {{calling a private constructor of class 'std::__1::future<int &>'}}
}
{
- typedef void T;
- std::future<T> f0;
- std::future<T> f = f0;
- assert(!f0.valid());
- assert(!f.valid());
+ std::future<void> f0;
+ std::future<void> f = f0; // expected-error {{calling a private constructor of class 'std::__1::future<void>'}}
}
+#endif
}
diff --git a/test/std/thread/futures/futures.unique_future/dtor.pass.cpp b/test/std/thread/futures/futures.unique_future/dtor.pass.cpp
index 5e9697bb939b..03d7c915cb61 100644
--- a/test/std/thread/futures/futures.unique_future/dtor.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/dtor.pass.cpp
@@ -7,7 +7,9 @@
//
//===----------------------------------------------------------------------===//
//
+// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
// <future>
@@ -18,51 +20,51 @@
#include <future>
#include <cassert>
-#include "../test_allocator.h"
+#include "test_allocator.h"
int main()
{
- assert(test_alloc_base::count == 0);
+ assert(test_alloc_base::alloc_count == 0);
{
typedef int T;
std::future<T> f;
{
std::promise<T> p(std::allocator_arg, test_allocator<T>());
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
f = p.get_future();
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 0);
+ assert(test_alloc_base::alloc_count == 0);
{
typedef int& T;
std::future<T> f;
{
std::promise<T> p(std::allocator_arg, test_allocator<int>());
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
f = p.get_future();
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 0);
+ assert(test_alloc_base::alloc_count == 0);
{
typedef void T;
std::future<T> f;
{
std::promise<T> p(std::allocator_arg, test_allocator<T>());
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
f = p.get_future();
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 1);
+ assert(test_alloc_base::alloc_count == 1);
assert(f.valid());
}
- assert(test_alloc_base::count == 0);
+ assert(test_alloc_base::alloc_count == 0);
}
diff --git a/test/std/thread/futures/futures.unique_future/get.pass.cpp b/test/std/thread/futures/futures.unique_future/get.pass.cpp
index 758e38a7dae9..67b1052c175d 100644
--- a/test/std/thread/futures/futures.unique_future/get.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/get.pass.cpp
@@ -7,7 +7,9 @@
//
//===----------------------------------------------------------------------===//
//
+// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
// <future>
diff --git a/test/std/thread/futures/futures.unique_future/share.pass.cpp b/test/std/thread/futures/futures.unique_future/share.pass.cpp
index 794b5ce38feb..ef011d8df752 100644
--- a/test/std/thread/futures/futures.unique_future/share.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/share.pass.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
// <future>
diff --git a/test/std/thread/futures/futures.unique_future/wait.pass.cpp b/test/std/thread/futures/futures.unique_future/wait.pass.cpp
index e10d37cf8064..f6de983f3057 100644
--- a/test/std/thread/futures/futures.unique_future/wait.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/wait.pass.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
// <future>
diff --git a/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp b/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
index 0a381d9ca2f0..c4f358268432 100644
--- a/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
// <future>
diff --git a/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp b/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
index d5865b9b9dcf..541c00860752 100644
--- a/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
+++ b/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
@@ -1,129 +1,130 @@
- //===----------------------------------------------------------------------===//
- //
- // 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
-
- // <future>
-
- // class future<R>
-
- // template <class Clock, class Duration>
- // future_status
- // wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
-
- #include <future>
- #include <atomic>
- #include <cassert>
-
- enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
- typedef std::chrono::milliseconds ms;
-
- std::atomic<WorkerThreadState> thread_state(WorkerThreadState::Uninitialized);
-
- void set_worker_thread_state(WorkerThreadState state)
- {
- thread_state.store(state, std::memory_order_relaxed);
- }
-
- void wait_for_worker_thread_state(WorkerThreadState state)
- {
- while (thread_state.load(std::memory_order_relaxed) != state);
- }
-
- void func1(std::promise<int> p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- p.set_value(3);
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- int j = 0;
-
- void func3(std::promise<int&> p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- j = 5;
- p.set_value(j);
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- void func5(std::promise<void> p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- p.set_value();
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- int main()
- {
- typedef std::chrono::high_resolution_clock Clock;
- {
- typedef int T;
- std::promise<T> p;
- std::future<T> f = p.get_future();
- std::thread(func1, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
- assert(f.valid());
- Clock::time_point t0 = Clock::now();
- f.wait();
- Clock::time_point t1 = Clock::now();
- assert(f.valid());
- assert(t1-t0 < ms(5));
- }
- {
- typedef int& T;
- std::promise<T> p;
- std::future<T> f = p.get_future();
- std::thread(func3, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
- assert(f.valid());
- Clock::time_point t0 = Clock::now();
- f.wait();
- Clock::time_point t1 = Clock::now();
- assert(f.valid());
- assert(t1-t0 < ms(5));
- }
- {
- typedef void T;
- std::promise<T> p;
- std::future<T> f = p.get_future();
- std::thread(func5, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
- assert(f.valid());
- Clock::time_point t0 = Clock::now();
- f.wait();
- Clock::time_point t1 = Clock::now();
- assert(f.valid());
- assert(t1-t0 < ms(5));
- }
- }
+//===----------------------------------------------------------------------===//
+//
+// 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 future<R>
+
+// template <class Clock, class Duration>
+// future_status
+// wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+
+#include <future>
+#include <atomic>
+#include <cassert>
+
+enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
+typedef std::chrono::milliseconds ms;
+
+std::atomic<WorkerThreadState> thread_state(WorkerThreadState::Uninitialized);
+
+void set_worker_thread_state(WorkerThreadState state)
+{
+ thread_state.store(state, std::memory_order_relaxed);
+}
+
+void wait_for_worker_thread_state(WorkerThreadState state)
+{
+ while (thread_state.load(std::memory_order_relaxed) != state);
+}
+
+void func1(std::promise<int> p)
+{
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ p.set_value(3);
+ set_worker_thread_state(WorkerThreadState::Exiting);
+}
+
+int j = 0;
+
+void func3(std::promise<int&> p)
+{
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ j = 5;
+ p.set_value(j);
+ set_worker_thread_state(WorkerThreadState::Exiting);
+}
+
+void func5(std::promise<void> p)
+{
+ wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
+ p.set_value();
+ set_worker_thread_state(WorkerThreadState::Exiting);
+}
+
+int main()
+{
+ typedef std::chrono::high_resolution_clock Clock;
+ {
+ typedef int T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func1, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef int& T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func3, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+ {
+ typedef void T;
+ std::promise<T> p;
+ std::future<T> f = p.get_future();
+ std::thread(func5, std::move(p)).detach();
+ assert(f.valid());
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
+ assert(f.valid());
+
+ // allow the worker thread to produce the result and wait until the worker is done
+ set_worker_thread_state(WorkerThreadState::AllowedToRun);
+ wait_for_worker_thread_state(WorkerThreadState::Exiting);
+
+ assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::ready);
+ assert(f.valid());
+ Clock::time_point t0 = Clock::now();
+ f.wait();
+ Clock::time_point t1 = Clock::now();
+ assert(f.valid());
+ assert(t1-t0 < ms(5));
+ }
+}