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