]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / rethrow_exception.cc
1 // { dg-do run { target c++11 } }
2
3 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
4
5 // Copyright (C) 2008-2021 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // rethrow_exception() and preservation of data
23
24 #include <exception>
25 #include <typeinfo>
26 #include <cstring>
27 #include <stdexcept>
28 #include <testsuite_hooks.h>
29
30 void test01()
31 {
32 using namespace std;
33
34 try {
35 rethrow_exception(make_exception_ptr(0));
36 } catch(...) {
37 }
38 }
39
40 void test02()
41 {
42 using namespace std;
43
44 try {
45 rethrow_exception(make_exception_ptr(runtime_error("test")));
46 } catch(exception &e) {
47 VERIFY( typeid(e) == typeid(runtime_error) );
48 VERIFY( strcmp(e.what(), "test") == 0 );
49 }
50 }
51
52 void test03()
53 {
54 using namespace std;
55
56 exception_ptr ep;
57 try {
58 throw 0;
59 } catch(...) {
60 ep = current_exception();
61 }
62 try {
63 rethrow_exception(ep);
64 } catch(...) {
65 }
66 }
67
68 void test04()
69 {
70 using namespace std;
71
72 // Weave the exceptions in an attempt to confuse the machinery.
73 try {
74 throw 0;
75 } catch(...) {
76 exception_ptr ep1 = current_exception();
77 try {
78 throw 1;
79 } catch(...) {
80 exception_ptr ep2 = current_exception();
81 try {
82 rethrow_exception(ep1);
83 } catch(...) {
84 try {
85 rethrow_exception(ep2);
86 } catch(...) {
87 try {
88 rethrow_exception(ep1);
89 } catch(...) {
90 }
91 try {
92 rethrow_exception(ep2);
93 } catch(...) {
94 }
95 }
96 }
97 }
98 }
99 }
100
101 void test05()
102 {
103 // libstdc++/64651 std::rethrow_exception not found by ADL
104 // This is not required to work but is a conforming extension.
105 try {
106 rethrow_exception(std::make_exception_ptr(0));
107 } catch(...) {
108 }
109 }
110
111 int main()
112 {
113 test01();
114 test02();
115 test03();
116 test04();
117 test05();
118
119 return 0;
120 }