OSDN Git Service

d71097fb1d60774c946991ac242f3eef21b433a3
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 30_threads / shared_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.7 Class template shared_future [futures.shared_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::shared_future<int> f;
37   try
38   {
39     f.get();
40     VERIFY( false );
41   }
42   catch (std::future_error& e)
43   {
44     VERIFY( e.code() == std::future_errc::no_state );
45   }
46 }
47
48 void
49 test02()
50 {
51   bool test __attribute__((unused)) = true;
52
53   std::shared_future<int&> f;
54   try
55   {
56     f.get();
57     VERIFY( false );
58   }
59   catch (std::future_error& e)
60   {
61     VERIFY( e.code() == std::future_errc::no_state );
62   }
63 }
64
65 void
66 test03()
67 {
68   bool test __attribute__((unused)) = true;
69
70   std::shared_future<void> f;
71   try
72   {
73     f.get();
74     VERIFY( false );
75   }
76   catch (std::future_error& e)
77   {
78     VERIFY( e.code() == std::future_errc::no_state );
79   }
80 }
81
82 int main()
83 {
84   test01();
85   test02();
86   test03();
87
88   return 0;
89 }
90