1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // Copyright (C) 2011 Vicente J. Botet Escriba
11 //
12 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
13 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14 
15 // <boost/thread/future.hpp>
16 
17 // class promise<R>
18 
19 // void promise<void>::set_value();
20 
21 #define BOOST_THREAD_VERSION 3
22 
23 #include <boost/thread/future.hpp>
24 #include <boost/detail/lightweight_test.hpp>
25 #include <boost/static_assert.hpp>
26 
27 struct A
28 {
AA29   A()
30   {
31   }
AA32   A(const A&)
33   {
34     throw 10;
35   }
36 };
37 
main()38 int main()
39 {
40 
41   {
42     typedef void T;
43     boost::promise<T> p;
44     boost::future<T> f = p.get_future();
45     p.set_value();
46     f.get();
47     try
48     {
49       p.set_value();
50       BOOST_TEST(false);
51     }
52     catch (const boost::future_error& e)
53     {
54       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
55     }
56     catch (...)
57     {
58       BOOST_TEST(false);
59     }
60   }
61   {
62     typedef void T;
63     boost::promise<T> p;
64     boost::future<T> f = p.get_future();
65     p.set_value_deferred();
66     p.notify_deferred();
67     f.get();
68     try
69     {
70       p.set_value();
71       BOOST_TEST(false);
72     }
73     catch (const boost::future_error& e)
74     {
75       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
76     }
77     catch (...)
78     {
79       BOOST_TEST(false);
80     }
81   }
82   return boost::report_errors();
83 }
84 
85