match: Optimize `max(a,b) == 0` to `(a|b) == 0` for unsigned [PR115275]
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / rethrow_exception.cc
blobb5e58da277b31ea276823ec8dbc9da55f5af13fd
1 // { dg-do run { target c++11 } }
3 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
5 // Copyright (C) 2008-2024 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.
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.
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/>.
22 // rethrow_exception() and preservation of data
24 #include <exception>
25 #include <typeinfo>
26 #include <cstring>
27 #include <stdexcept>
28 #include <testsuite_hooks.h>
30 void test01()
32 using namespace std;
34 try {
35 rethrow_exception(make_exception_ptr(0));
36 } catch(...) {
40 void test02()
42 using namespace std;
44 try {
45 rethrow_exception(make_exception_ptr(runtime_error("test")));
46 } catch(exception &e) {
47 #if __cpp_rtti
48 VERIFY( typeid(e) == typeid(runtime_error) );
49 #endif
50 VERIFY( strcmp(e.what(), "test") == 0 );
54 void test03()
56 using namespace std;
58 exception_ptr ep;
59 try {
60 throw 0;
61 } catch(...) {
62 ep = current_exception();
64 try {
65 rethrow_exception(ep);
66 } catch(...) {
70 void test04()
72 using namespace std;
74 // Weave the exceptions in an attempt to confuse the machinery.
75 try {
76 throw 0;
77 } catch(...) {
78 exception_ptr ep1 = current_exception();
79 try {
80 throw 1;
81 } catch(...) {
82 exception_ptr ep2 = current_exception();
83 try {
84 rethrow_exception(ep1);
85 } catch(...) {
86 try {
87 rethrow_exception(ep2);
88 } catch(...) {
89 try {
90 rethrow_exception(ep1);
91 } catch(...) {
93 try {
94 rethrow_exception(ep2);
95 } catch(...) {
103 void test05()
105 // libstdc++/64651 std::rethrow_exception not found by ADL
106 // This is not required to work but is a conforming extension.
107 try {
108 rethrow_exception(std::make_exception_ptr(0));
109 } catch(...) {
113 int main()
115 test01();
116 test02();
117 test03();
118 test04();
119 test05();
121 return 0;