OSDN Git Service

In gcc/objc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / exceptions-2.m
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-do run } */
3 /* { dg-options "-fobjc-exceptions" } */
4 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */
6
7 /* This test checks the syntax @catch (...) which catches any
8    exceptions.  Check that code using it runs correctly.  */
9
10 #include "../objc-obj-c++-shared/Object1.h"
11 #include <stdlib.h>
12
13 @interface MyObject : Object
14 @end
15
16 @implementation MyObject
17 @end
18
19 int test (id object)
20 {
21   int i = 0;
22
23   @try
24     {
25       @throw object;
26     }
27   @catch (MyObject *o)
28     {
29       i += 1;
30     }
31   @catch (...)
32     {
33       i += 2;
34     }
35   @finally
36     {
37       i += 4;
38     }
39
40   return i;
41 }
42
43 int main (void)
44 {
45   if (test ([MyObject new]) != 5)
46     abort ();
47
48   if (test ([Object new]) != 6)
49     abort ();
50
51   return 0;
52 }