1 /* This test script is part of GDB, the GNU debugger. 2 3 Copyright 2002-2017 Free Software Foundation, Inc. 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 7 the Free Software Foundation; either version 3 of the License, or 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. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include <exception> 19 #include <stdexcept> 20 #include <string> 21 22 enum region { oriental, egyptian, greek, etruscan, roman }; 23 24 // Test one. 25 class gnu_obj_1 26 { 27 public: 28 typedef region antiquities; 29 const bool test; 30 const int key1; 31 long key2; 32 33 antiquities value; 34 35 gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {} 36 }; 37 38 // Test two. 39 template<typename T> 40 class gnu_obj_2: public virtual gnu_obj_1 41 { 42 public: 43 antiquities value_derived; 44 45 gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { } 46 }; 47 48 // Test three. 49 template<typename T> 50 class gnu_obj_3 51 { 52 public: 53 typedef region antiquities; 54 gnu_obj_2<int> data; 55 56 gnu_obj_3(antiquities b): data(etruscan) { } 57 }; 58 59 int main() 60 { 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; 71 throw gnu_obj_1(egyptian, 4589); // marker 1-throw 72 } 73 catch (gnu_obj_1& obj) 74 { 75 ++j; 76 if (obj.value != egyptian) // marker 1-catch 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 { 90 ++j; // marker 2-start 91 try 92 { 93 ++j; // marker 2-next 94 try 95 { 96 ++j; 97 throw gnu_obj_1(egyptian, 4589); // marker 2-throw 98 } 99 catch (gnu_obj_1& obj) 100 { 101 ++j; 102 if (obj.value != egyptian) // marker 2-catch 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) 128 throw invalid_argument("gdb.1"); // marker 3-throw 129 } 130 catch (exception& obj) 131 { 132 if (obj.what() != "gdb.1") // marker 3-catch 133 test &= false; 134 } 135 return 0; 136 } 137