]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc
Add exception propagation support as per N2179.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / current_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 // current_exception() under various conditions.
23
24 #include <exception>
25 #include <testsuite_hooks.h>
26
27 void test01()
28 {
29 bool test __attribute__((unused)) = true;
30 using namespace std;
31
32 exception_ptr ep = current_exception();
33 VERIFY( !ep );
34 }
35
36 void test02()
37 {
38 bool test __attribute__((unused)) = true;
39 using namespace std;
40
41 try {
42 throw 0;
43 } catch(...) {
44 exception_ptr ep = current_exception();
45 VERIFY( ep );
46 }
47 }
48
49 void test03()
50 {
51 bool test __attribute__((unused)) = true;
52 using namespace std;
53
54 try {
55 throw exception();
56 } catch(std::exception&) {
57 exception_ptr ep = current_exception();
58 VERIFY( ep );
59 }
60 }
61
62 void test04()
63 {
64 bool test __attribute__((unused)) = true;
65 using namespace std;
66
67 try {
68 throw 0;
69 } catch(...) {
70 exception_ptr ep1 = current_exception();
71 try {
72 throw 0;
73 } catch(...) {
74 exception_ptr ep2 = current_exception();
75 VERIFY( ep1 != ep2 );
76 }
77 exception_ptr ep3 = current_exception();
78 // Not guaranteed by standard, but by this implementation.
79 VERIFY( ep1 == ep3 );
80 }
81 }
82
83 int main()
84 {
85 test01();
86 test02();
87 test03();
88 test04();
89 return 0;
90 }