• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03
11 // UNSUPPORTED: libcpp-has-no-threads, libcpp-no-exceptions
12 
13 // <future>
14 
15 // class promise<R>
16 
17 // void promise::set_value(R&& r);
18 
19 #include <future>
20 #include <memory>
21 #include <cassert>
22 
23 struct A
24 {
AA25     A() {}
26     A(const A&) = delete;
AA27     A(A&&) {throw 9;}
28 };
29 
main()30 int main()
31 {
32     {
33         typedef std::unique_ptr<int> T;
34         T i(new int(3));
35         std::promise<T> p;
36         std::future<T> f = p.get_future();
37         p.set_value(std::move(i));
38         assert(*f.get() == 3);
39         try
40         {
41             p.set_value(std::move(i));
42             assert(false);
43         }
44         catch (const std::future_error& e)
45         {
46             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
47         }
48     }
49     {
50         typedef A T;
51         T i;
52         std::promise<T> p;
53         std::future<T> f = p.get_future();
54         try
55         {
56             p.set_value(std::move(i));
57             assert(false);
58         }
59         catch (int j)
60         {
61             assert(j == 9);
62         }
63     }
64 }
65