OSDN Git Service

a4e4551d8955bff07b4d291cd8729d72ed74ebbc
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 30_threads / future / members / 45133.cc
1 // { dg-options "-std=gnu++0x" }
2 // { dg-require-cstdint "" }
3 // { dg-require-gthreads "" }
4 // { dg-require-atomic-builtins "" }
5
6 // Copyright (C) 2010 Free Software Foundation
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 {
34   bool test __attribute__((unused)) = true;
35
36   std::promise<int> p;
37   std::future<int> f = p.get_future();
38   p.set_value(0);
39   f.get();
40   try
41   {
42     f.get();
43     VERIFY( false );
44   }
45   catch (std::future_error& e)
46   {
47     VERIFY( e.code() == std::future_errc::no_state );
48   }
49 }
50
51 void
52 test02()
53 {
54   bool test __attribute__((unused)) = true;
55
56   std::promise<int&> p;
57   std::future<int&> f = p.get_future();
58   int i = 0;
59   p.set_value(i);
60   f.get();
61   try
62   {
63     f.get();
64     VERIFY( false );
65   }
66   catch (std::future_error& e)
67   {
68     VERIFY( e.code() == std::future_errc::no_state );
69   }
70 }
71
72 void
73 test03()
74 {
75   bool test __attribute__((unused)) = true;
76
77   std::promise<void> p;
78   std::future<void> f = p.get_future();
79   p.set_value();
80   f.get();
81   try
82   {
83     f.get();
84     VERIFY( false );
85   }
86   catch (std::future_error& e)
87   {
88     VERIFY( e.code() == std::future_errc::no_state );
89   }
90 }
91
92 int main()
93 {
94   test01();
95   test02();
96   test03();
97
98   return 0;
99 }
100