]> 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
RO
1// { dg-do run }
2// { dg-options "-pthread" }
71c54f8e 3// { dg-require-effective-target c++11 }
d1236680 4// { dg-require-effective-target pthread }
5262c72a 5// { dg-require-gthreads "" }
5262c72a 6
8d9254fc 7// Copyright (C) 2010-2020 Free Software Foundation, Inc.
5262c72a
JW
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// 30.6.6 Class template future [futures.unique_future]
25
26#include <future>
27#include <testsuite_hooks.h>
28
29// This test verifies behaviour which is encouraged by a non-normative note,
30// but not required.
31
32void
33test01()
34{
5262c72a
JW
35 std::promise<int> p;
36 std::future<int> f = p.get_future();
37 p.set_value(0);
38 f.get();
39 try
40 {
41 f.get();
42 VERIFY( false );
43 }
44 catch (std::future_error& e)
45 {
46 VERIFY( e.code() == std::future_errc::no_state );
47 }
48}
49
50void
51test02()
52{
5262c72a
JW
53 std::promise<int&> p;
54 std::future<int&> f = p.get_future();
55 int i = 0;
56 p.set_value(i);
57 f.get();
58 try
59 {
60 f.get();
61 VERIFY( false );
62 }
63 catch (std::future_error& e)
64 {
65 VERIFY( e.code() == std::future_errc::no_state );
66 }
67}
68
69void
70test03()
71{
5262c72a
JW
72 std::promise<void> p;
73 std::future<void> f = p.get_future();
74 p.set_value();
75 f.get();
76 try
77 {
78 f.get();
79 VERIFY( false );
80 }
81 catch (std::future_error& e)
82 {
83 VERIFY( e.code() == std::future_errc::no_state );
84 }
85}
86
87int main()
88{
89 test01();
90 test02();
91 test03();
92
93 return 0;
94}
95