]>
Commit | Line | Data |
---|---|---|
d1236680 | 1 | // { dg-do run } |
1e42d2f4 | 2 | // { dg-additional-options "-pthread" { target pthread } } |
71c54f8e | 3 | // { dg-require-effective-target c++11 } |
5262c72a | 4 | // { dg-require-gthreads "" } |
5262c72a | 5 | |
83ffe9cd | 6 | // Copyright (C) 2010-2023 Free Software Foundation, Inc. |
5262c72a JW |
7 | // |
8 | // This file is part of the GNU ISO C++ Library. This library is free | |
9 | // software; you can redistribute it and/or modify it under the | |
10 | // terms of the GNU General Public License as published by the | |
11 | // Free Software Foundation; either version 3, or (at your option) | |
12 | // any later version. | |
13 | ||
14 | // This library is distributed in the hope that it will be useful, | |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | // GNU General Public License for more details. | |
18 | ||
19 | // You should have received a copy of the GNU General Public License along | |
20 | // with this library; see the file COPYING3. If not see | |
21 | // <http://www.gnu.org/licenses/>. | |
22 | ||
23 | // 30.6.6 Class template future [futures.unique_future] | |
24 | ||
25 | #include <future> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | // This test verifies behaviour which is encouraged by a non-normative note, | |
29 | // but not required. | |
30 | ||
31 | void | |
32 | test01() | |
33 | { | |
5262c72a JW |
34 | std::promise<int> p; |
35 | std::future<int> f = p.get_future(); | |
36 | p.set_value(0); | |
37 | f.get(); | |
38 | try | |
39 | { | |
40 | f.get(); | |
41 | VERIFY( false ); | |
42 | } | |
43 | catch (std::future_error& e) | |
44 | { | |
45 | VERIFY( e.code() == std::future_errc::no_state ); | |
46 | } | |
47 | } | |
48 | ||
49 | void | |
50 | test02() | |
51 | { | |
5262c72a JW |
52 | std::promise<int&> p; |
53 | std::future<int&> f = p.get_future(); | |
54 | int i = 0; | |
55 | p.set_value(i); | |
56 | f.get(); | |
57 | try | |
58 | { | |
59 | f.get(); | |
60 | VERIFY( false ); | |
61 | } | |
62 | catch (std::future_error& e) | |
63 | { | |
64 | VERIFY( e.code() == std::future_errc::no_state ); | |
65 | } | |
66 | } | |
67 | ||
68 | void | |
69 | test03() | |
70 | { | |
5262c72a JW |
71 | std::promise<void> p; |
72 | std::future<void> f = p.get_future(); | |
73 | p.set_value(); | |
74 | f.get(); | |
75 | try | |
76 | { | |
77 | f.get(); | |
78 | VERIFY( false ); | |
79 | } | |
80 | catch (std::future_error& e) | |
81 | { | |
82 | VERIFY( e.code() == std::future_errc::no_state ); | |
83 | } | |
84 | } | |
85 | ||
86 | int main() | |
87 | { | |
88 | test01(); | |
89 | test02(); | |
90 | test03(); | |
91 | ||
92 | return 0; | |
93 | } | |
94 |