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 { 16 const int i; 17 int j; 18 }; 19 20 typedef const int A::*md1; 21 typedef int A::*md2; 22 23 struct B : public A 24 { 25 const int k; 26 int l; 27 }; 28 29 typedef const int B::*der1; 30 typedef int B::*der2; 31 32 void test1() 33 { 34 try 35 { 36 throw &A::i; 37 assert(false); 38 } 39 catch (md2) 40 { 41 assert(false); 42 } 43 catch (md1) 44 { 45 } 46 } 47 48 // Check that cv qualified conversions are allowed. 49 void test2() 50 { 51 try 52 { 53 throw &A::j; 54 } 55 catch (md2) 56 { 57 } 58 catch (...) 59 { 60 assert(false); 61 } 62 63 try 64 { 65 throw &A::j; 66 assert(false); 67 } 68 catch (md1) 69 { 70 } 71 catch (...) 72 { 73 assert(false); 74 } 75 } 76 77 // Check that Base -> Derived conversions are NOT allowed. 78 void test3() 79 { 80 try 81 { 82 throw &A::i; 83 assert(false); 84 } 85 catch (md2) 86 { 87 assert(false); 88 } 89 catch (der2) 90 { 91 assert(false); 92 } 93 catch (der1) 94 { 95 assert(false); 96 } 97 catch (md1) 98 { 99 } 100 } 101 102 // Check that Base -> Derived conversions NOT are allowed with different cv 103 // qualifiers. 104 void test4() 105 { 106 try 107 { 108 throw &A::j; 109 assert(false); 110 } 111 catch (der2) 112 { 113 assert(false); 114 } 115 catch (der1) 116 { 117 assert(false); 118 } 119 catch (md2) 120 { 121 } 122 catch (...) 123 { 124 assert(false); 125 } 126 } 127 128 // Check that no Derived -> Base conversions are allowed. 129 void test5() 130 { 131 try 132 { 133 throw &B::k; 134 assert(false); 135 } 136 catch (md1) 137 { 138 assert(false); 139 } 140 catch (md2) 141 { 142 assert(false); 143 } 144 catch (der1) 145 { 146 } 147 148 try 149 { 150 throw &B::l; 151 assert(false); 152 } 153 catch (md1) 154 { 155 assert(false); 156 } 157 catch (md2) 158 { 159 assert(false); 160 } 161 catch (der2) 162 { 163 } 164 } 165 166 int main() 167 { 168 test1(); 169 test2(); 170 test3(); 171 test4(); 172 test5(); 173 } 174