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