[multiple changes]
[gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / current_exception.cc
1 // { dg-options "-std=gnu++0x" }
2 // { dg-require-atomic-builtins "" }
3
4 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
5
6 // Copyright (C) 2008 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 2, or (at your option)
12 // any later version.
13
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING. If not, write to the Free
21 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // USA.
23
24 // current_exception() under various conditions.
25
26 #include <exception>
27 #include <testsuite_hooks.h>
28
29 void test01()
30 {
31 bool test __attribute__((unused)) = true;
32 using namespace std;
33
34 exception_ptr ep = current_exception();
35 VERIFY( !ep );
36 }
37
38 void test02()
39 {
40 bool test __attribute__((unused)) = true;
41 using namespace std;
42
43 try {
44 throw 0;
45 } catch(...) {
46 exception_ptr ep = current_exception();
47 VERIFY( ep );
48 }
49 }
50
51 void test03()
52 {
53 bool test __attribute__((unused)) = true;
54 using namespace std;
55
56 try {
57 throw exception();
58 } catch(std::exception&) {
59 exception_ptr ep = current_exception();
60 VERIFY( ep );
61 }
62 }
63
64 void test04()
65 {
66 bool test __attribute__((unused)) = true;
67 using namespace std;
68
69 try {
70 throw 0;
71 } catch(...) {
72 exception_ptr ep1 = current_exception();
73 try {
74 throw 0;
75 } catch(...) {
76 exception_ptr ep2 = current_exception();
77 VERIFY( ep1 != ep2 );
78 }
79 exception_ptr ep3 = current_exception();
80 // Not guaranteed by standard, but by this implementation.
81 VERIFY( ep1 == ep3 );
82 }
83 }
84
85 int main()
86 {
87 test01();
88 test02();
89 test03();
90 test04();
91 return 0;
92 }