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