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// <exception>
11
12// template<class E> exception_ptr make_exception_ptr(E e);
13
14#include <exception>
15#include <cassert>
16
17#include "test_macros.h"
18
19struct A
20{
21 static int constructed;
22 int data_;
23
24 A(int data = 0) : data_(data) {++constructed;}
25 ~A() {--constructed;}
26 A(const A& a) : data_(a.data_) {++constructed;}
27};
28
29int A::constructed = 0;
30
31int main(int, char**)
32{
33 {
34 std::exception_ptr p = std::make_exception_ptr(ex: A(5));
35 try
36 {
37 std::rethrow_exception(p);
38 assert(false);
39 }
40 catch (const A& a)
41 {
42#ifndef TEST_ABI_MICROSOFT
43 assert(A::constructed == 1);
44#else
45 // On Windows exception_ptr copies the exception
46 assert(A::constructed == 2);
47#endif
48 assert(p != nullptr);
49 p = nullptr;
50 assert(p == nullptr);
51 assert(a.data_ == 5);
52 assert(A::constructed == 1);
53 }
54 assert(A::constructed == 0);
55 }
56 assert(A::constructed == 0);
57
58 return 0;
59}
60

source code of libcxx/test/std/language.support/support.exception/propagation/make_exception_ptr.pass.cpp