| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-options "-fobjc-exceptions" } */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
// { dg-additional-options "-Wno-objc-root-class" } |
| 5 |
|
| 6 |
/* Test warnings when parsing syntax errors in @catch(). */ |
| 7 |
|
| 8 |
#include <objc/objc.h> |
| 9 |
|
| 10 |
@interface MyObject |
| 11 |
{ |
| 12 |
Class isa; |
| 13 |
} |
| 14 |
@end |
| 15 |
|
| 16 |
@implementation MyObject |
| 17 |
@end |
| 18 |
|
| 19 |
@interface MyObject2 |
| 20 |
{ |
| 21 |
Class isa; |
| 22 |
} |
| 23 |
@end |
| 24 |
|
| 25 |
@implementation MyObject2 |
| 26 |
@end |
| 27 |
|
| 28 |
@protocol MyProtocol; |
| 29 |
|
| 30 |
int test (id object) |
| 31 |
{ |
| 32 |
int dummy = 0; |
| 33 |
|
| 34 |
@try { @throw object; } |
| 35 |
@catch |
| 36 |
{ /* { dg-error "expected" } */ |
| 37 |
dummy++; /* { dg-error "'@catch' parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */ |
| 38 |
} |
| 39 |
@catch () /* { dg-error "expected identifier before" } */ |
| 40 |
{ /* { dg-error "'@catch' parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */ |
| 41 |
dummy++; |
| 42 |
} |
| 43 |
@catch (i) /* { dg-error ".i. has not been declared" } */ |
| 44 |
{ /* { dg-error "'@catch' parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */ |
| 45 |
dummy++; |
| 46 |
} |
| 47 |
@catch (id <MyProtocol x) /* { dg-error "expected ... before .x." } */ |
| 48 |
{ /* { dg-error "'@catch' parameter cannot be protocol-qualified" "" { target *-*-* } .-1 } */ |
| 49 |
dummy++; |
| 50 |
} |
| 51 |
@catch MyObject *x /* { dg-error "expected ... before .MyObject." } */ |
| 52 |
{ |
| 53 |
dummy++; |
| 54 |
} |
| 55 |
@catch MyObject2 *x) /* { dg-error "expected ... before .MyObject2." } */ |
| 56 |
{ |
| 57 |
dummy++; |
| 58 |
} |
| 59 |
|
| 60 |
@try { @throw object; } |
| 61 |
@catch (MyObject *x) |
| 62 |
@catch (MyObject2 *y) /* { dg-error "expected ... before .catch." } */ |
| 63 |
|
| 64 |
return dummy; /* { dg-error "expected ... before .return." } */ |
| 65 |
} |