Switch the license of all .c files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / try_catch.cc
1 /* This test script is part of GDB, the GNU debugger.
2
3 Copyright 2002, 2004,
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <exception>
21 #include <stdexcept>
22 #include <string>
23
24 enum region { oriental, egyptian, greek, etruscan, roman };
25
26 // Test one.
27 class gnu_obj_1
28 {
29 public:
30 typedef region antiquities;
31 const bool test;
32 const int key1;
33 long key2;
34
35 antiquities value;
36
37 gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {}
38 };
39
40 // Test two.
41 template<typename T>
42 class gnu_obj_2: public virtual gnu_obj_1
43 {
44 public:
45 antiquities value_derived;
46
47 gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { }
48 };
49
50 // Test three.
51 template<typename T>
52 class gnu_obj_3
53 {
54 public:
55 typedef region antiquities;
56 gnu_obj_2<int> data;
57
58 gnu_obj_3(antiquities b): data(etruscan) { }
59 };
60
61 int main()
62 {
63 bool test = true;
64 const int i = 5;
65 int j = i;
66 gnu_obj_2<long> test2(roman);
67 gnu_obj_3<long> test3(greek);
68
69 // 1
70 try
71 {
72 ++j;
73 throw gnu_obj_1(egyptian, 4589); // marker 1-throw
74 }
75 catch (gnu_obj_1& obj)
76 {
77 ++j;
78 if (obj.value != egyptian) // marker 1-catch
79 test &= false;
80 if (obj.key2 != 4589)
81 test &= false;
82 }
83 catch (...)
84 {
85 j = 0;
86 test &= false;
87 }
88
89 // 2
90 try
91 {
92 ++j; // marker 2-start
93 try
94 {
95 ++j; // marker 2-next
96 try
97 {
98 ++j;
99 throw gnu_obj_1(egyptian, 4589); // marker 2-throw
100 }
101 catch (gnu_obj_1& obj)
102 {
103 ++j;
104 if (obj.value != egyptian) // marker 2-catch
105 test &= false;
106 if (obj.key2 != 4589)
107 test &= false;
108 }
109 }
110 catch (gnu_obj_1& obj)
111 {
112 ++j;
113 if (obj.value != egyptian)
114 test &= false;
115 if (obj.key2 != 4589)
116 test &= false;
117 }
118 }
119 catch (...)
120 {
121 j = 0;
122 test &= false;
123 }
124
125 // 3 use standard library
126 using namespace std;
127 try
128 {
129 if (j < 100)
130 throw invalid_argument("gdb.1"); // marker 3-throw
131 }
132 catch (exception& obj)
133 {
134 if (obj.what() != "gdb.1") // marker 3-catch
135 test &= false;
136 }
137 return 0;
138 }
This page took 0.078475 seconds and 4 git commands to generate.