]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/30_threads/future/members/45133.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 30_threads / future / members / 45133.cc
CommitLineData
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
31void
32test01()
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
49void
50test02()
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
68void
69test03()
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
86int main()
87{
88 test01();
89 test02();
90 test03();
91
92 return 0;
93}
94