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