]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc
96d38d5eba3edf76c9ae50e0f155444002507ac3
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / rethrow_exception.cc
1 // { dg-options "-std=gnu++0x" }
2 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
3
4 // Copyright (C) 2008 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
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 bool test __attribute__((unused)) = true;
33 using namespace std;
34
35 try {
36 rethrow_exception(copy_exception(0));
37 } catch(...) {
38 }
39 }
40
41 void test02()
42 {
43 bool test __attribute__((unused)) = true;
44 using namespace std;
45
46 try {
47 rethrow_exception(copy_exception(runtime_error("test")));
48 } catch(exception &e) {
49 VERIFY( typeid(e) == typeid(runtime_error) );
50 VERIFY( strcmp(e.what(), "test") == 0 );
51 }
52 }
53
54 void test03()
55 {
56 bool test __attribute__((unused)) = true;
57 using namespace std;
58
59 exception_ptr ep;
60 try {
61 throw 0;
62 } catch(...) {
63 ep = current_exception();
64 }
65 try {
66 rethrow_exception(ep);
67 } catch(...) {
68 }
69 }
70
71 void test04()
72 {
73 bool test __attribute__((unused)) = true;
74 using namespace std;
75
76 // Weave the exceptions in an attempt to confuse the machinery.
77 try {
78 throw 0;
79 } catch(...) {
80 exception_ptr ep1 = current_exception();
81 try {
82 throw 1;
83 } catch(...) {
84 exception_ptr ep2 = current_exception();
85 try {
86 rethrow_exception(ep1);
87 } catch(...) {
88 try {
89 rethrow_exception(ep2);
90 } catch(...) {
91 try {
92 rethrow_exception(ep1);
93 } catch(...) {
94 }
95 try {
96 rethrow_exception(ep2);
97 } catch(...) {
98 }
99 }
100 }
101 }
102 }
103 }
104
105 int main()
106 {
107 test01();
108 test02();
109 test03();
110 test04();
111
112 return 0;
113 }