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 // <exception>
11 
12 // void rethrow_exception [[noreturn]] (exception_ptr p);
13 
14 #include <exception>
15 #include <cassert>
16 
17 struct A
18 {
19     static int constructed;
20     int data_;
21 
22     A(int data = 0) : data_(data) {++constructed;}
23     ~A() {--constructed;}
24     A(const A& a) : data_(a.data_) {++constructed;}
25 };
26 
27 int A::constructed = 0;
28 
29 int main()
30 {
31     {
32         std::exception_ptr p;
33         try
34         {
35             throw A(3);
36         }
37         catch (...)
38         {
39             p = std::current_exception();
40         }
41         try
42         {
43             std::rethrow_exception(p);
44             assert(false);
45         }
46         catch (const A& a)
47         {
48             assert(A::constructed == 1);
49             assert(p != nullptr);
50             p = nullptr;
51             assert(p == nullptr);
52             assert(a.data_ == 3);
53             assert(A::constructed == 1);
54         }
55         assert(A::constructed == 0);
56     }
57 }
58