]>
Commit | Line | Data |
---|---|---|
a8815ed2 | 1 | // { dg-do run } |
2 | // { dg-options "-pthread" } | |
e12be0dd | 3 | // { dg-require-effective-target c++11 } |
a8815ed2 | 4 | // { dg-require-effective-target pthread } |
e12be0dd | 5 | // { dg-require-gthreads "" } |
6 | ||
fbd26352 | 7 | // Copyright (C) 2014-2019 Free Software Foundation, Inc. |
e12be0dd | 8 | // |
9 | // This file is part of the GNU ISO C++ Library. This library is free | |
10 | // software; you can redistribute it and/or modify it under the | |
11 | // terms of the GNU General Public License as published by the | |
12 | // Free Software Foundation; either version 3, or (at your option) | |
13 | // any later version. | |
14 | ||
15 | // This library is distributed in the hope that it will be useful, | |
16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | // GNU General Public License for more details. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License along | |
21 | // with this library; see the file COPYING3. If not see | |
22 | // <http://www.gnu.org/licenses/>. | |
23 | ||
24 | // Test set_value_at_thread_exit error conditions | |
25 | ||
26 | #include <future> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | void test01() | |
30 | { | |
31 | std::promise<int> p1; | |
32 | p1.set_value(1); | |
33 | try | |
34 | { | |
35 | p1.set_value_at_thread_exit(2); | |
36 | VERIFY( false ); | |
37 | } | |
38 | catch (std::future_error& e) | |
39 | { | |
40 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
41 | } | |
42 | try | |
43 | { | |
44 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
45 | VERIFY( false ); | |
46 | } | |
47 | catch (std::future_error& e) | |
48 | { | |
49 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
50 | } | |
51 | ||
52 | std::promise<int> p2(std::move(p1)); | |
53 | try | |
54 | { | |
55 | p1.set_value_at_thread_exit(2); | |
56 | VERIFY( false ); | |
57 | } | |
58 | catch (std::future_error& e) | |
59 | { | |
60 | VERIFY( e.code() == std::future_errc::no_state ); | |
61 | } | |
62 | try | |
63 | { | |
64 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
65 | VERIFY( false ); | |
66 | } | |
67 | catch (std::future_error& e) | |
68 | { | |
69 | VERIFY( e.code() == std::future_errc::no_state ); | |
70 | } | |
71 | } | |
72 | ||
73 | void test02() | |
74 | { | |
75 | std::promise<int&> p1; | |
76 | int i = 1; | |
77 | p1.set_value(i); | |
78 | try | |
79 | { | |
80 | p1.set_value_at_thread_exit(i); | |
81 | VERIFY( false ); | |
82 | } | |
83 | catch (std::future_error& e) | |
84 | { | |
85 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
86 | } | |
87 | try | |
88 | { | |
89 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
90 | VERIFY( false ); | |
91 | } | |
92 | catch (std::future_error& e) | |
93 | { | |
94 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
95 | } | |
96 | ||
97 | std::promise<int&> p2(std::move(p1)); | |
98 | try | |
99 | { | |
100 | int i = 0; | |
101 | p1.set_value_at_thread_exit(i); | |
102 | VERIFY( false ); | |
103 | } | |
104 | catch (std::future_error& e) | |
105 | { | |
106 | VERIFY( e.code() == std::future_errc::no_state ); | |
107 | } | |
108 | try | |
109 | { | |
110 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
111 | VERIFY( false ); | |
112 | } | |
113 | catch (std::future_error& e) | |
114 | { | |
115 | VERIFY( e.code() == std::future_errc::no_state ); | |
116 | } | |
117 | } | |
118 | ||
119 | void test03() | |
120 | { | |
121 | std::promise<void> p1; | |
122 | int i = 0; | |
123 | p1.set_value(); | |
124 | try { | |
125 | p1.set_value_at_thread_exit(); | |
126 | VERIFY( false ); | |
127 | } | |
128 | catch (std::future_error& e) | |
129 | { | |
130 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
131 | } | |
132 | try | |
133 | { | |
134 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
135 | VERIFY( false ); | |
136 | } | |
137 | catch (std::future_error& e) | |
138 | { | |
139 | VERIFY( e.code() == std::future_errc::promise_already_satisfied ); | |
140 | } | |
141 | ||
142 | std::promise<void> p2(std::move(p1)); | |
143 | try { | |
144 | p1.set_value_at_thread_exit(); | |
145 | VERIFY( false ); | |
146 | } | |
147 | catch (std::future_error& e) | |
148 | { | |
149 | VERIFY( e.code() == std::future_errc::no_state ); | |
150 | } | |
151 | try | |
152 | { | |
153 | p1.set_exception_at_thread_exit(std::make_exception_ptr(3)); | |
154 | VERIFY( false ); | |
155 | } | |
156 | catch (std::future_error& e) | |
157 | { | |
158 | VERIFY( e.code() == std::future_errc::no_state ); | |
159 | } | |
160 | } | |
161 | ||
162 | int main() | |
163 | { | |
164 | test01(); | |
165 | test02(); | |
166 | test03(); | |
167 | } |