OSDN Git Service

2006-02-08 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.eh / catchptr1.C
1 // { dg-do run  }
2 // Test pointer chain catching
3 // Copyright (C) 2000, 2002 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 9 Apr 2000 <nathan@nathan@codesourcery.com>
5
6 #include <stdio.h>
7
8 void fn () {}
9 struct A {void fn () {}};
10 static int var = 1;
11 static const int const_var = 2;
12
13 struct B;
14 struct C;
15
16 int test0 ()
17 {
18   try
19     {
20       throw &fn;
21     }
22   catch (void *)
23     {
24       // should not decay to void *
25       return 1;
26     }
27   catch (...)
28     {
29       return 0;
30     }
31   return -1;
32 }
33
34 int test1 ()
35 {
36   try
37     {
38       throw &A::fn;
39     }
40   catch (void *)
41     {
42       // should not decay to void *
43       return 1;
44     }
45   catch (...)
46     {
47       return 0;
48     }
49   return -1;
50 }
51
52 int test2 ()
53 {
54   try
55     {
56       throw &var;
57     }
58   catch (void *)
59     {
60       // should decay to void *
61       return 0;
62     }
63   catch (...)
64     {
65       return 1;
66     }
67   return -1;
68 }
69
70 int test3 ()
71 {
72   try
73     {
74       throw &var;
75     }
76   catch (void const *)
77     {
78       // should decay to const void *
79       return 0;
80     }
81   catch (...)
82     {
83       return 1;
84     }
85   return -1;
86 }
87
88 int test4 ()
89 {
90   try
91     {
92       throw &const_var;
93     }
94   catch (void *)
95     {
96       // should not decay to void *
97       return 1;
98     }
99   catch (void const *)
100     {
101       // should decay to const void *
102       return 0;
103     }
104   catch (...)
105     {
106       return 2;
107     }
108   return -1;
109 }
110
111 int test5 ()
112 {
113   try
114     {
115       throw (void ***)0;
116     }
117   catch (void ***)
118     {
119       return 0;
120     }
121   catch (...)
122     {
123       return 1;
124     }
125   return -1;
126 }
127
128 int test6 ()
129 {
130   try
131     {
132       throw (void const* const* const*)0;
133     }
134   catch (void ***)
135     {
136       return 1;
137     }
138   catch (void * const* const*)
139     {
140       return 2;
141     }
142   catch (void const* * const*)
143     {
144       return 3;
145     }
146   catch (void const* const* *)
147     {
148       return 4;
149     }
150   catch (void const* const* const *)
151     {
152       return 0;
153     }
154   catch (...)
155     {
156       return 1;
157     }
158   return -1;
159 }
160
161 int test7 ()
162 {
163   try
164     {
165       throw (void ***)0;
166     }
167   catch (void const* const**)
168     {
169       return 1;
170     }
171   catch (void const** const *)
172     {
173       return 2;
174     }
175   catch (void * const* const *)
176     {
177       return 0;
178     }
179   catch (...)
180     {
181       return 3;
182     }
183   return -1;
184 }
185
186 int test8 ()
187 {
188   try
189     {
190       throw (B **)0;
191     }
192   catch (C **)
193     {
194       return 1;
195     }
196   catch (B **)
197     {
198       return 0;
199     }
200   catch (...)
201     {
202       return 2;
203     }
204   return -1;
205 }
206
207 int test9 ()
208 {
209   try
210     {
211       throw (B **)0;
212     }
213   catch (C const *const *)
214     {
215       return 1;
216     }
217   catch (B const *const *)
218     {
219       return 0;
220     }
221   catch (...)
222     {
223       return 2;
224     }
225   return -1;
226 }
227
228 static int (*tests[])() =
229 {
230   test0,
231   test1,
232   test2,
233   test3,
234   test4,
235   
236   test5,
237   test6,
238   test7,
239   
240   test8,
241   test9,
242   
243   NULL
244 };
245
246 int main ()
247 {
248   int ix;
249   int errors = 0;
250   
251   for (ix = 0; tests[ix]; ix++)
252     {
253       int n = tests[ix] ();
254       
255       if (n)
256         {
257           printf ("test %d failed %d\n", ix, n);
258           errors++;
259         }
260     }
261   return errors;
262 }