2004-06-13 Michael Chastain <mec.gnu@mindspring.com>
[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 2 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include <exception>
22 #include <stdexcept>
23 #include <string>
24
25 enum region { oriental, egyptian, greek, etruscan, roman };
26
27 // Test one.
28 class gnu_obj_1
29 {
30 public:
31 typedef region antiquities;
32 const bool test;
33 const int key1;
34 long key2;
35
36 antiquities value;
37
38 gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {}
39 };
40
41 // Test two.
42 template<typename T>
43 class gnu_obj_2: public virtual gnu_obj_1
44 {
45 public:
46 antiquities value_derived;
47
48 gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { }
49 };
50
51 // Test three.
52 template<typename T>
53 class gnu_obj_3
54 {
55 public:
56 typedef region antiquities;
57 gnu_obj_2<int> data;
58
59 gnu_obj_3(antiquities b): data(etruscan) { }
60 };
61
62 int main()
63 {
64 bool test = true;
65 const int i = 5;
66 int j = i;
67 gnu_obj_2<long> test2(roman);
68 gnu_obj_3<long> test3(greek);
69
70 // 1
71 try
72 {
73 ++j;
74 throw gnu_obj_1(egyptian, 4589); // marker 1-throw
75 }
76 catch (gnu_obj_1& obj)
77 {
78 ++j;
79 if (obj.value != egyptian) // marker 1-catch
80 test &= false;
81 if (obj.key2 != 4589)
82 test &= false;
83 }
84 catch (...)
85 {
86 j = 0;
87 test &= false;
88 }
89
90 // 2
91 try
92 {
93 ++j; // marker 2-start
94 try
95 {
96 ++j; // marker 2-next
97 try
98 {
99 ++j;
100 throw gnu_obj_1(egyptian, 4589); // marker 2-throw
101 }
102 catch (gnu_obj_1& obj)
103 {
104 ++j;
105 if (obj.value != egyptian) // marker 2-catch
106 test &= false;
107 if (obj.key2 != 4589)
108 test &= false;
109 }
110 }
111 catch (gnu_obj_1& obj)
112 {
113 ++j;
114 if (obj.value != egyptian)
115 test &= false;
116 if (obj.key2 != 4589)
117 test &= false;
118 }
119 }
120 catch (...)
121 {
122 j = 0;
123 test &= false;
124 }
125
126 // 3 use standard library
127 using namespace std;
128 try
129 {
130 if (j < 100)
131 throw invalid_argument("gdb.1"); // marker 3-throw
132 }
133 catch (exception& obj)
134 {
135 if (obj.what() != "gdb.1") // marker 3-catch
136 test &= false;
137 }
138 return 0;
139 }
This page took 0.034758 seconds and 5 git commands to generate.