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: no-threads
11// UNSUPPORTED: c++03
12
13// <future>
14
15// class promise<R>
16
17// void promise::set_exception_at_thread_exit(exception_ptr p);
18
19#include <future>
20#include <cassert>
21
22#include "make_test_thread.h"
23#include "test_macros.h"
24
25void func(std::promise<int> p)
26{
27 p.set_exception_at_thread_exit(std::make_exception_ptr(ex: 3));
28}
29
30int main(int, char**)
31{
32 {
33 typedef int T;
34 std::promise<T> p;
35 std::future<T> f = p.get_future();
36 support::make_test_thread(func, std::move(p)).detach();
37 try
38 {
39 f.get();
40 assert(false);
41 }
42 catch (int i)
43 {
44 assert(i == 3);
45 }
46 }
47
48 return 0;
49}
50

source code of libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp