1 //===----------------- catch_member_data_pointer_01.cpp -------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: libcxxabi-no-exceptions 11 12 #include <cassert> 13 14 struct A 15 { AA16 A() : i(0), j(0) {} // explicitly initialize 'i' to prevent warnings 17 const int i; 18 int j; 19 }; 20 21 typedef const int A::*md1; 22 typedef int A::*md2; 23 24 struct B : public A 25 { BB26 B() : k(0), l(0) {} // explicitly initialize 'k' to prevent warnings. 27 const int k; 28 int l; 29 }; 30 31 typedef const int B::*der1; 32 typedef int B::*der2; 33 test1()34void test1() 35 { 36 try 37 { 38 throw &A::i; 39 assert(false); 40 } 41 catch (md2) 42 { 43 assert(false); 44 } 45 catch (md1) 46 { 47 } 48 } 49 50 // Check that cv qualified conversions are allowed. test2()51void test2() 52 { 53 try 54 { 55 throw &A::j; 56 } 57 catch (md2) 58 { 59 } 60 catch (...) 61 { 62 assert(false); 63 } 64 65 try 66 { 67 throw &A::j; 68 assert(false); 69 } 70 catch (md1) 71 { 72 } 73 catch (...) 74 { 75 assert(false); 76 } 77 } 78 79 // Check that Base -> Derived conversions are NOT allowed. test3()80void test3() 81 { 82 try 83 { 84 throw &A::i; 85 assert(false); 86 } 87 catch (md2) 88 { 89 assert(false); 90 } 91 catch (der2) 92 { 93 assert(false); 94 } 95 catch (der1) 96 { 97 assert(false); 98 } 99 catch (md1) 100 { 101 } 102 } 103 104 // Check that Base -> Derived conversions NOT are allowed with different cv 105 // qualifiers. test4()106void test4() 107 { 108 try 109 { 110 throw &A::j; 111 assert(false); 112 } 113 catch (der2) 114 { 115 assert(false); 116 } 117 catch (der1) 118 { 119 assert(false); 120 } 121 catch (md2) 122 { 123 } 124 catch (...) 125 { 126 assert(false); 127 } 128 } 129 130 // Check that no Derived -> Base conversions are allowed. test5()131void test5() 132 { 133 try 134 { 135 throw &B::k; 136 assert(false); 137 } 138 catch (md1) 139 { 140 assert(false); 141 } 142 catch (md2) 143 { 144 assert(false); 145 } 146 catch (der1) 147 { 148 } 149 150 try 151 { 152 throw &B::l; 153 assert(false); 154 } 155 catch (md1) 156 { 157 assert(false); 158 } 159 catch (md2) 160 { 161 assert(false); 162 } 163 catch (der2) 164 { 165 } 166 } 167 main()168int main() 169 { 170 test1(); 171 test2(); 172 test3(); 173 test4(); 174 test5(); 175 } 176