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