OSDN Git Service

2005-10-22 David Ayers <d.ayers@inode.at>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / except-1.mm
1 /* { dg-do run } */
2
3 /* This tests that exceptions work.  It used to fail because
4    objc_msgSend was marked with DECL_NOTHROW. 
5    If you include objc/Object.h, the problem goes away, because
6    that file includes objc/objc-runtime.h which explicitly prototypes
7    objc_msgSend without 'nothrow'.  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12
13 @interface Object {
14   Class isa;  
15 }
16 + alloc;
17 - init;
18 @end
19
20 // ObjectiveC class header
21 @interface ObjCclass : Object {
22 }
23 -(void)method1;
24 -(void)method2;
25 @end
26
27 // C++ class header
28 class CPPclass {
29 public:
30         void function1();
31 };
32
33
34 // Main
35 int main(int argc, char *argv[])
36 {
37         ObjCclass * foo = [[ObjCclass alloc] init];
38         [foo method1];
39         exit (0);
40 }
41
42
43 // ObjectiveC implementation
44 @implementation ObjCclass
45
46 -(void) method1
47 {
48         try {
49                 [self method2];
50         }
51         catch(...) {
52                 return;
53         }
54 }
55
56 -(void) method2
57 {
58         CPPclass foo;
59         foo.function1();
60 }
61
62 @end
63
64
65 // C++ implementation
66 void CPPclass::function1()
67 {
68         throw (1);
69         /* Shouldn't be here because we threw.  */
70         abort ();
71 }