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 // <future>
11 
12 // class promise<R>
13 
14 // void set_exception(exception_ptr p);
15 
16 #include <future>
17 #include <cassert>
18 
main()19 int main()
20 {
21     {
22         typedef int T;
23         std::promise<T> p;
24         std::future<T> f = p.get_future();
25         p.set_exception(std::make_exception_ptr(3));
26         try
27         {
28             f.get();
29             assert(false);
30         }
31         catch (int i)
32         {
33             assert(i == 3);
34         }
35         try
36         {
37             p.set_exception(std::make_exception_ptr(3));
38             assert(false);
39         }
40         catch (const std::future_error& e)
41         {
42             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
43         }
44     }
45 }
46