1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <future>
11 
12 // class promise<R>
13 
14 // promise& operator=(const promise& rhs) = delete;
15 
16 #include <future>
17 #include <cassert>
18 
19 #include "../test_allocator.h"
20 
main()21 int main()
22 {
23     assert(test_alloc_base::count == 0);
24     {
25         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
26         std::promise<int> p(std::allocator_arg, test_allocator<int>());
27         assert(test_alloc_base::count == 2);
28         p = p0;
29         assert(test_alloc_base::count == 1);
30         std::future<int> f = p.get_future();
31         assert(test_alloc_base::count == 1);
32         assert(f.valid());
33         try
34         {
35             f = p0.get_future();
36             assert(false);
37         }
38         catch (const std::future_error& e)
39         {
40             assert(e.code() == make_error_code(std::future_errc::no_state));
41         }
42         assert(test_alloc_base::count == 1);
43     }
44     assert(test_alloc_base::count == 0);
45     {
46         std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
47         std::promise<int&> p(std::allocator_arg, test_allocator<int>());
48         assert(test_alloc_base::count == 2);
49         p = p0;
50         assert(test_alloc_base::count == 1);
51         std::future<int&> f = p.get_future();
52         assert(test_alloc_base::count == 1);
53         assert(f.valid());
54         try
55         {
56             f = p0.get_future();
57             assert(false);
58         }
59         catch (const std::future_error& e)
60         {
61             assert(e.code() == make_error_code(std::future_errc::no_state));
62         }
63         assert(test_alloc_base::count == 1);
64     }
65     assert(test_alloc_base::count == 0);
66     {
67         std::promise<void> p0(std::allocator_arg, test_allocator<void>());
68         std::promise<void> p(std::allocator_arg, test_allocator<void>());
69         assert(test_alloc_base::count == 2);
70         p = p0;
71         assert(test_alloc_base::count == 1);
72         std::future<void> f = p.get_future();
73         assert(test_alloc_base::count == 1);
74         assert(f.valid());
75         try
76         {
77             f = p0.get_future();
78             assert(false);
79         }
80         catch (const std::future_error& e)
81         {
82             assert(e.code() == make_error_code(std::future_errc::no_state));
83         }
84         assert(test_alloc_base::count == 1);
85     }
86     assert(test_alloc_base::count == 0);
87 }
88