blob: eeec4fb15b956c35db0b569bcb85298ccac84d03 [file] [log] [blame]
Howard Hinnantf39daa82010-08-28 21:01:06 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantf39daa82010-08-28 21:01:06 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnantf39daa82010-08-28 21:01:06 +000011
12// <future>
13
14// class promise<R>
15
16// promise(promise&& rhs);
17
18#include <future>
19#include <cassert>
20
Dan Albert1d4a1ed2016-05-25 22:36:09 -070021#include "../test_allocator.h"
Howard Hinnantf39daa82010-08-28 21:01:06 +000022
23int main()
24{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
26 assert(test_alloc_base::count == 0);
Howard Hinnantf39daa82010-08-28 21:01:06 +000027 {
28 std::promise<int> p0(std::allocator_arg, test_allocator<int>());
29 std::promise<int> p(std::move(p0));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000031 std::future<int> f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070032 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000033 assert(f.valid());
34 try
35 {
36 f = p0.get_future();
37 assert(false);
38 }
39 catch (const std::future_error& e)
40 {
41 assert(e.code() == make_error_code(std::future_errc::no_state));
42 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070043 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000044 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070045 assert(test_alloc_base::count == 0);
Howard Hinnantf39daa82010-08-28 21:01:06 +000046 {
47 std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
48 std::promise<int&> p(std::move(p0));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000050 std::future<int&> f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070051 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000052 assert(f.valid());
53 try
54 {
55 f = p0.get_future();
56 assert(false);
57 }
58 catch (const std::future_error& e)
59 {
60 assert(e.code() == make_error_code(std::future_errc::no_state));
61 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070062 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000063 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070064 assert(test_alloc_base::count == 0);
Howard Hinnantf39daa82010-08-28 21:01:06 +000065 {
66 std::promise<void> p0(std::allocator_arg, test_allocator<void>());
67 std::promise<void> p(std::move(p0));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070068 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000069 std::future<void> f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070070 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000071 assert(f.valid());
72 try
73 {
74 f = p0.get_future();
75 assert(false);
76 }
77 catch (const std::future_error& e)
78 {
79 assert(e.code() == make_error_code(std::future_errc::no_state));
80 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070081 assert(test_alloc_base::count == 1);
Howard Hinnantf39daa82010-08-28 21:01:06 +000082 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070083 assert(test_alloc_base::count == 0);
84#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000085}