1//===------------------------- catch_ptr_02.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 {};
13A a;
14const A ca = A();
15
16void test1 ()
17{
18    try
19    {
20        throw &a;
21        assert(false);
22    }
23    catch ( const A* )
24    {
25    }
26    catch ( A *)
27    {
28        assert (false);
29    }
30}
31
32void test2 ()
33{
34    try
35     {
36        throw &a;
37        assert(false);
38    }
39    catch ( A* )
40    {
41    }
42    catch ( const A *)
43    {
44         assert (false);
45    }
46}
47
48void test3 ()
49{
50    try
51    {
52        throw &ca;
53        assert(false);
54    }
55    catch ( const A* )
56    {
57    }
58    catch ( A *)
59    {
60        assert (false);
61    }
62}
63
64void test4 ()
65{
66    try
67    {
68        throw &ca;
69        assert(false);
70    }
71    catch ( A *)
72    {
73        assert (false);
74    }
75    catch ( const A* )
76    {
77    }
78}
79
80struct base1 {int x;};
81struct base2 {int x;};
82struct derived : base1, base2 {};
83
84void test5 ()
85{
86    try
87    {
88        throw (derived*)0;
89        assert(false);
90    }
91    catch (base2 *p) {
92        assert (p == 0);
93    }
94    catch (...)
95    {
96        assert (false);
97    }
98}
99
100void test6 ()
101{
102    try
103    {
104        throw nullptr;
105        assert(false);
106    }
107    catch (base2 *p) {
108        assert (p == nullptr);
109    }
110    catch (...)
111    {
112        assert (false);
113    }
114}
115
116void test7 ()
117{
118    try
119    {
120        throw (derived*)12;
121        assert(false);
122    }
123    catch (base2 *p) {
124        assert ((unsigned long)p == 12+sizeof(base1));
125    }
126    catch (...)
127    {
128        assert (false);
129    }
130}
131
132
133struct vBase {};
134struct vDerived : virtual public vBase {};
135
136void test8 ()
137{
138    vDerived derived;
139    try
140    {
141        throw &derived;
142        assert(false);
143    }
144    catch (vBase *p) {
145        assert(p != 0);
146    }
147    catch (...)
148    {
149        assert (false);
150    }
151}
152
153void test9 ()
154{
155    try
156    {
157        throw nullptr;
158        assert(false);
159    }
160    catch (vBase *p) {
161        assert(p == 0);
162    }
163    catch (...)
164    {
165        assert (false);
166    }
167}
168
169void test10 ()
170{
171    try
172    {
173        throw (vDerived*)0;
174        assert(false);
175    }
176    catch (vBase *p) {
177        assert(p == 0);
178    }
179    catch (...)
180    {
181        assert (false);
182    }
183}
184
185int main()
186{
187    test1();
188    test2();
189    test3();
190    test4();
191    test5();
192    test6();
193    test7();
194    test8();
195    test9();
196    test10();
197}
198