• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-exceptions
10 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++03
12 
13 // <future>
14 
15 // class promise<R>
16 
17 // void set_exception(exception_ptr p);
18 
19 #include <future>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
main(int,char **)24 int main(int, char**)
25 {
26     {
27         typedef int T;
28         std::promise<T> p;
29         std::future<T> f = p.get_future();
30         p.set_exception(std::make_exception_ptr(3));
31         try
32         {
33             f.get();
34             assert(false);
35         }
36         catch (int i)
37         {
38             assert(i == 3);
39         }
40         try
41         {
42             p.set_exception(std::make_exception_ptr(3));
43             assert(false);
44         }
45         catch (const std::future_error& e)
46         {
47             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
48         }
49     }
50 
51   return 0;
52 }
53