Dead
[official-gcc.git] / gomp-20050608-branch / gcc / testsuite / g++.old-deja / g++.eh / catchptr1.C
blob2d2467548ea7f50900b79ca1498953f485cbacd5
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>
6 #include <stdio.h>
8 void fn () {}
9 struct A {void fn () {}};
10 static int var = 1;
11 static const int const_var = 2;
13 struct B;
14 struct C;
16 int test0 ()
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;
34 int test1 ()
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;
52 int test2 ()
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;
70 int test3 ()
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;
88 int test4 ()
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;
111 int test5 ()
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;
128 int test6 ()
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;
161 int test7 ()
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;
186 int test8 ()
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;
207 int test9 ()
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;
228 static int (*tests[])() =
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
246 int main ()
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;