blob: 298a1c0256189e4a622cf2748e91cd65c6e4cc05 [file] [log] [blame]
Howard Hinnantc649bde2012-02-01 20:53:21 +00001//===----------------- 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
12struct A
13{
14 const int i;
15 int j;
16};
17
18typedef const int A::*md1;
19typedef int A::*md2;
20
Eric Fiselier0cb62d12015-04-02 23:26:37 +000021struct B : public A
22{
23 const int k;
24 int l;
25};
26
27typedef const int B::*der1;
28typedef int B::*der2;
29
Howard Hinnantc649bde2012-02-01 20:53:21 +000030void 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 Fiselier0cb62d12015-04-02 23:26:37 +000046// Check that cv qualified conversions are allowed.
Howard Hinnantc649bde2012-02-01 20:53:21 +000047void test2()
48{
49 try
50 {
51 throw &A::j;
Eric Fiselier0cb62d12015-04-02 23:26:37 +000052 }
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.
76void 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.
102void 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.
132void test5()
133{
134 try
135 {
136 throw &B::k;
Howard Hinnantc649bde2012-02-01 20:53:21 +0000137 assert(false);
138 }
139 catch (md1)
140 {
141 assert(false);
142 }
143 catch (md2)
144 {
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000145 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 Hinnantc649bde2012-02-01 20:53:21 +0000166 }
167}
168
169int main()
170{
171 test1();
172 test2();
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000173 test3();
174 test4();
175 test5();
Howard Hinnantc649bde2012-02-01 20:53:21 +0000176}