blob: c6427efc238d445ff8ac51a1c9e6ea52e8f64a07 [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
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +000010// UNSUPPORTED: libcxxabi-no-exceptions
11
Howard Hinnantc649bde2012-02-01 20:53:21 +000012#include <cassert>
13
14struct A
15{
16 const int i;
17 int j;
18};
19
20typedef const int A::*md1;
21typedef int A::*md2;
22
Eric Fiselier0cb62d12015-04-02 23:26:37 +000023struct B : public A
24{
25 const int k;
26 int l;
27};
28
29typedef const int B::*der1;
30typedef int B::*der2;
31
Howard Hinnantc649bde2012-02-01 20:53:21 +000032void 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 Fiselier0cb62d12015-04-02 23:26:37 +000048// Check that cv qualified conversions are allowed.
Howard Hinnantc649bde2012-02-01 20:53:21 +000049void test2()
50{
51 try
52 {
53 throw &A::j;
Eric Fiselier0cb62d12015-04-02 23:26:37 +000054 }
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 Fiselier554d59a2015-04-06 23:03:01 +000077// Check that Base -> Derived conversions are NOT allowed.
Eric Fiselier0cb62d12015-04-02 23:26:37 +000078void 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 Fiselier554d59a2015-04-06 23:03:01 +000095 assert(false);
Eric Fiselier0cb62d12015-04-02 23:26:37 +000096 }
97 catch (md1)
98 {
Eric Fiselier0cb62d12015-04-02 23:26:37 +000099 }
100}
101
Eric Fiselier554d59a2015-04-06 23:03:01 +0000102// Check that Base -> Derived conversions NOT are allowed with different cv
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000103// qualifiers.
104void test4()
105{
106 try
107 {
108 throw &A::j;
109 assert(false);
110 }
111 catch (der2)
112 {
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000113 assert(false);
114 }
115 catch (der1)
116 {
Eric Fiselier554d59a2015-04-06 23:03:01 +0000117 assert(false);
118 }
119 catch (md2)
120 {
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000121 }
122 catch (...)
123 {
124 assert(false);
125 }
126}
127
128// Check that no Derived -> Base conversions are allowed.
129void test5()
130{
131 try
132 {
133 throw &B::k;
Howard Hinnantc649bde2012-02-01 20:53:21 +0000134 assert(false);
135 }
136 catch (md1)
137 {
138 assert(false);
139 }
140 catch (md2)
141 {
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000142 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 Hinnantc649bde2012-02-01 20:53:21 +0000163 }
164}
165
166int main()
167{
168 test1();
169 test2();
Eric Fiselier0cb62d12015-04-02 23:26:37 +0000170 test3();
171 test4();
172 test5();
Howard Hinnantc649bde2012-02-01 20:53:21 +0000173}