| 1 |
/* Contributed by Nicola Pero <[email protected]>, December 2010. */ |
| 2 |
/* { dg-options "-fobjc-exceptions" } */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
// { dg-additional-options "-Wno-objc-root-class" } |
| 5 |
|
| 6 |
/* Test that the compiler is checking the argument of @synchronized(), |
| 7 |
and produce errors when invalid types are used. */ |
| 8 |
|
| 9 |
#include <objc/objc.h> |
| 10 |
|
| 11 |
@interface MyObject |
| 12 |
{ |
| 13 |
Class isa; |
| 14 |
} |
| 15 |
@end |
| 16 |
|
| 17 |
@implementation MyObject |
| 18 |
@end |
| 19 |
|
| 20 |
@protocol MyProtocol; |
| 21 |
|
| 22 |
typedef MyObject MyObjectTypedef; |
| 23 |
typedef MyObject *MyObjectPtrTypedef; |
| 24 |
typedef int intTypedef; |
| 25 |
|
| 26 |
typedef struct { float x; float y; } point, *point_ptr; |
| 27 |
|
| 28 |
int test (id object) |
| 29 |
{ |
| 30 |
int dummy = 0; |
| 31 |
|
| 32 |
{ |
| 33 |
int x; |
| 34 |
@synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 35 |
{ dummy++; } |
| 36 |
} |
| 37 |
|
| 38 |
{ |
| 39 |
intTypedef x; |
| 40 |
@synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 41 |
{ dummy++; } |
| 42 |
} |
| 43 |
|
| 44 |
{ |
| 45 |
int *x; |
| 46 |
@synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 47 |
{ dummy++; } |
| 48 |
} |
| 49 |
|
| 50 |
{ |
| 51 |
point x; |
| 52 |
@synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 53 |
{ dummy++; } |
| 54 |
} |
| 55 |
|
| 56 |
{ |
| 57 |
point_ptr x; |
| 58 |
@synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 59 |
{ dummy++; } |
| 60 |
} |
| 61 |
|
| 62 |
{ |
| 63 |
id x; |
| 64 |
@synchronized (x) /* Ok */ |
| 65 |
{ dummy++; } |
| 66 |
} |
| 67 |
|
| 68 |
{ |
| 69 |
id <MyProtocol> x; |
| 70 |
@synchronized (x) /* Ok */ |
| 71 |
{ dummy++; } |
| 72 |
} |
| 73 |
|
| 74 |
{ |
| 75 |
MyObject *x; |
| 76 |
@synchronized (x) /* Ok */ |
| 77 |
{ dummy++; } |
| 78 |
} |
| 79 |
|
| 80 |
{ |
| 81 |
MyObject <MyProtocol> *x; |
| 82 |
@synchronized (x) /* Ok */ |
| 83 |
{ dummy++; } |
| 84 |
} |
| 85 |
|
| 86 |
{ |
| 87 |
static MyObject *x; |
| 88 |
@synchronized (x) /* Ok */ |
| 89 |
{ dummy++; } |
| 90 |
} |
| 91 |
|
| 92 |
{ |
| 93 |
MyObjectTypedef *x; |
| 94 |
@synchronized (x) /* Ok */ |
| 95 |
{ dummy++; } |
| 96 |
} |
| 97 |
|
| 98 |
{ |
| 99 |
MyObjectTypedef <MyProtocol> *x; |
| 100 |
@synchronized (x) /* Ok */ |
| 101 |
{ dummy++; } |
| 102 |
} |
| 103 |
|
| 104 |
{ |
| 105 |
MyObjectPtrTypedef x; |
| 106 |
@synchronized (x) /* Ok */ |
| 107 |
{ dummy++; } |
| 108 |
} |
| 109 |
|
| 110 |
{ |
| 111 |
Class x; |
| 112 |
@synchronized (x) /* Ok */ |
| 113 |
{ dummy++; } |
| 114 |
} |
| 115 |
|
| 116 |
@synchronized (1) /* { dg-error ".@synchronized. argument is not an object" } */ |
| 117 |
{ dummy++; } |
| 118 |
|
| 119 |
@synchronized ("Test") /* { dg-error ".@synchronized. argument is not an object" } */ |
| 120 |
{ dummy++; } |
| 121 |
|
| 122 |
@synchronized () /* { dg-error "expected" } */ |
| 123 |
{ dummy++; } |
| 124 |
|
| 125 |
@synchronized (int) /* { dg-error "expected" } */ |
| 126 |
{ dummy++; } |
| 127 |
|
| 128 |
return dummy; |
| 129 |
} |