[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.promise / move_assign.pass.cpp
blob350db2acf2f9a8fe2f8242e0000216626e7a14cc
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03
12 // <future>
14 // class promise<R>
16 // promise& operator=(promise&& rhs);
18 #include <future>
19 #include <cassert>
21 #include "test_macros.h"
22 #include "test_allocator.h"
24 int main(int, char**)
26 test_allocator_statistics alloc_stats;
27 assert(alloc_stats.alloc_count == 0);
29 std::promise<int> p0(std::allocator_arg, test_allocator<int>(&alloc_stats));
30 std::promise<int> p(std::allocator_arg, test_allocator<int>(&alloc_stats));
31 assert(alloc_stats.alloc_count == 2);
32 p = std::move(p0);
33 assert(alloc_stats.alloc_count == 1);
34 std::future<int> f = p.get_future();
35 assert(alloc_stats.alloc_count == 1);
36 assert(f.valid());
37 #ifndef TEST_HAS_NO_EXCEPTIONS
38 try
40 f = p0.get_future();
41 assert(false);
43 catch (const std::future_error& e)
45 assert(e.code() == make_error_code(std::future_errc::no_state));
47 #endif
48 assert(alloc_stats.alloc_count == 1);
50 assert(alloc_stats.alloc_count == 0);
52 std::promise<int&> p0(std::allocator_arg, test_allocator<int>(&alloc_stats));
53 std::promise<int&> p(std::allocator_arg, test_allocator<int>(&alloc_stats));
54 assert(alloc_stats.alloc_count == 2);
55 p = std::move(p0);
56 assert(alloc_stats.alloc_count == 1);
57 std::future<int&> f = p.get_future();
58 assert(alloc_stats.alloc_count == 1);
59 assert(f.valid());
60 #ifndef TEST_HAS_NO_EXCEPTIONS
61 try
63 f = p0.get_future();
64 assert(false);
66 catch (const std::future_error& e)
68 assert(e.code() == make_error_code(std::future_errc::no_state));
70 #endif
71 assert(alloc_stats.alloc_count == 1);
73 assert(alloc_stats.alloc_count == 0);
75 std::promise<void> p0(std::allocator_arg, test_allocator<void>(&alloc_stats));
76 std::promise<void> p(std::allocator_arg, test_allocator<void>(&alloc_stats));
77 assert(alloc_stats.alloc_count == 2);
78 p = std::move(p0);
79 assert(alloc_stats.alloc_count == 1);
80 std::future<void> f = p.get_future();
81 assert(alloc_stats.alloc_count == 1);
82 assert(f.valid());
83 #ifndef TEST_HAS_NO_EXCEPTIONS
84 try
86 f = p0.get_future();
87 assert(false);
89 catch (const std::future_error& e)
91 assert(e.code() == make_error_code(std::future_errc::no_state));
93 #endif
94 assert(alloc_stats.alloc_count == 1);
96 assert(alloc_stats.alloc_count == 0);
98 return 0;