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 | |||||
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame^] | 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
11 | |||||
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 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 | |||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 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 | |||||
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 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 | |||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 48 | // Check that cv qualified conversions are allowed. |
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 49 | void test2() |
50 | { | ||||
51 | try | ||||
52 | { | ||||
53 | throw &A::j; | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 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 | |||||
Eric Fiselier | 554d59a | 2015-04-06 23:03:01 +0000 | [diff] [blame] | 77 | // Check that Base -> Derived conversions are NOT allowed. |
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 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 | { | ||||
Eric Fiselier | 554d59a | 2015-04-06 23:03:01 +0000 | [diff] [blame] | 95 | assert(false); |
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 96 | } |
97 | catch (md1) | ||||
98 | { | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 99 | } |
100 | } | ||||
101 | |||||
Eric Fiselier | 554d59a | 2015-04-06 23:03:01 +0000 | [diff] [blame] | 102 | // Check that Base -> Derived conversions NOT are allowed with different cv |
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 103 | // qualifiers. |
104 | void test4() | ||||
105 | { | ||||
106 | try | ||||
107 | { | ||||
108 | throw &A::j; | ||||
109 | assert(false); | ||||
110 | } | ||||
111 | catch (der2) | ||||
112 | { | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 113 | assert(false); |
114 | } | ||||
115 | catch (der1) | ||||
116 | { | ||||
Eric Fiselier | 554d59a | 2015-04-06 23:03:01 +0000 | [diff] [blame] | 117 | assert(false); |
118 | } | ||||
119 | catch (md2) | ||||
120 | { | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 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; | ||||
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 134 | assert(false); |
135 | } | ||||
136 | catch (md1) | ||||
137 | { | ||||
138 | assert(false); | ||||
139 | } | ||||
140 | catch (md2) | ||||
141 | { | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 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 | { | ||||
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 163 | } |
164 | } | ||||
165 | |||||
166 | int main() | ||||
167 | { | ||||
168 | test1(); | ||||
169 | test2(); | ||||
Eric Fiselier | 0cb62d1 | 2015-04-02 23:26:37 +0000 | [diff] [blame] | 170 | test3(); |
171 | test4(); | ||||
172 | test5(); | ||||
Howard Hinnant | c649bde | 2012-02-01 20:53:21 +0000 | [diff] [blame] | 173 | } |