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