[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.promise / move_ctor.pass.cpp
blobb473c1b346fdf17b5a68db9ecbc1da9fb96f09aa
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(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::move(p0));
31 assert(alloc_stats.alloc_count == 1);
32 std::future<int> f = p.get_future();
33 assert(alloc_stats.alloc_count == 1);
34 assert(f.valid());
35 #ifndef TEST_HAS_NO_EXCEPTIONS
36 try
38 f = p0.get_future();
39 assert(false);
41 catch (const std::future_error& e)
43 assert(e.code() == make_error_code(std::future_errc::no_state));
45 assert(alloc_stats.alloc_count == 1);
46 #endif
48 assert(alloc_stats.alloc_count == 0);
50 std::promise<int&> p0(std::allocator_arg, test_allocator<int>(&alloc_stats));
51 std::promise<int&> p(std::move(p0));
52 assert(alloc_stats.alloc_count == 1);
53 std::future<int&> f = p.get_future();
54 assert(alloc_stats.alloc_count == 1);
55 assert(f.valid());
56 #ifndef TEST_HAS_NO_EXCEPTIONS
57 try
59 f = p0.get_future();
60 assert(false);
62 catch (const std::future_error& e)
64 assert(e.code() == make_error_code(std::future_errc::no_state));
66 assert(alloc_stats.alloc_count == 1);
67 #endif
69 assert(alloc_stats.alloc_count == 0);
71 std::promise<void> p0(std::allocator_arg, test_allocator<void>(&alloc_stats));
72 std::promise<void> p(std::move(p0));
73 assert(alloc_stats.alloc_count == 1);
74 std::future<void> f = p.get_future();
75 assert(alloc_stats.alloc_count == 1);
76 assert(f.valid());
77 #ifndef TEST_HAS_NO_EXCEPTIONS
78 try
80 f = p0.get_future();
81 assert(false);
83 catch (const std::future_error& e)
85 assert(e.code() == make_error_code(std::future_errc::no_state));
87 assert(alloc_stats.alloc_count == 1);
88 #endif
90 assert(alloc_stats.alloc_count == 0);
92 return 0;