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

source code of libcxxabi/test/catch_member_data_pointer_01.pass.cpp