[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.promise / dtor.pass.cpp
blob2ee79eaa2b6e0ae8188ae459f8f8c30c40315567
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();
18 #include <future>
19 #include <cassert>
21 #include "test_macros.h"
23 int main(int, char**)
26 typedef int T;
27 std::future<T> f;
29 std::promise<T> p;
30 f = p.get_future();
31 p.set_value(3);
33 assert(f.get() == 3);
35 #ifndef TEST_HAS_NO_EXCEPTIONS
37 typedef int T;
38 std::future<T> f;
40 std::promise<T> p;
41 f = p.get_future();
43 try
45 T i = f.get();
46 ((void)i); // Prevent unused warning
47 assert(false);
49 catch (const std::future_error& e)
51 assert(e.code() == make_error_code(std::future_errc::broken_promise));
54 #endif
57 typedef int& T;
58 int i = 4;
59 std::future<T> f;
61 std::promise<T> p;
62 f = p.get_future();
63 p.set_value(i);
65 assert(&f.get() == &i);
67 #ifndef TEST_HAS_NO_EXCEPTIONS
69 typedef int& T;
70 std::future<T> f;
72 std::promise<T> p;
73 f = p.get_future();
75 try
77 T i = f.get();
78 ((void)i); // Prevent unused warning
79 assert(false);
81 catch (const std::future_error& e)
83 assert(e.code() == make_error_code(std::future_errc::broken_promise));
86 #endif
89 typedef void T;
90 std::future<T> f;
92 std::promise<T> p;
93 f = p.get_future();
94 p.set_value();
96 f.get();
97 assert(true);
99 #ifndef TEST_HAS_NO_EXCEPTIONS
101 typedef void T;
102 std::future<T> f;
104 std::promise<T> p;
105 f = p.get_future();
109 f.get();
110 assert(false);
112 catch (const std::future_error& e)
114 // LWG 2056 changed the values of future_errc, so if we're using new
115 // headers with an old library the error codes won't line up.
117 // Note that this particular check only applies to promise<void>
118 // since the other specializations happen to be implemented in the
119 // header rather than the library.
120 assert(
121 e.code() == make_error_code(std::future_errc::broken_promise) ||
122 e.code() == std::error_code(0, std::future_category()));
125 #endif
127 return 0;