PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / objc.dg / sync-3.m
blob5cee890bba2e7db943b62cabd9412583cc0c5ecb
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
5 /* Test that the compiler is checking the argument of @synchronized(),
6    and produce errors when invalid types are used.  */
8 #include <objc/objc.h>
10 @interface MyObject
12   Class isa;
14 @end
16 @implementation MyObject
17 @end
19 @protocol MyProtocol;
21 typedef MyObject MyObjectTypedef;
22 typedef MyObject *MyObjectPtrTypedef;
23 typedef int intTypedef;
25 typedef struct { float x; float y; } point, *point_ptr;
27 int test (id object)
29   int dummy = 0;
31   {
32     int x;
33     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
34     { dummy++; }
35   }
37   {
38     intTypedef x;
39     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
40     { dummy++; }
41   }
43   {
44     int *x;
45     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
46     { dummy++; }
47   }
49   {
50     point x;
51     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
52     { dummy++; }
53   }
55   {
56     point_ptr x;
57     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
58     { dummy++; }
59   }
61   {
62     id x;
63     @synchronized (x) /* Ok */
64     { dummy++; }
65   }
67   {
68     id <MyProtocol> x;
69     @synchronized (x) /* Ok */
70     { dummy++; }
71   }
73   {
74     MyObject *x;
75     @synchronized (x) /* Ok */
76     { dummy++; }
77   }
79   {
80     MyObject <MyProtocol> *x;
81     @synchronized (x) /* Ok */
82     { dummy++; }
83   }
85   {
86     static MyObject *x;
87     @synchronized (x) /* Ok */
88     { dummy++; }
89   }
91   {
92     MyObjectTypedef *x;
93     @synchronized (x) /* Ok */
94     { dummy++; }
95   }
97   {
98     MyObjectTypedef <MyProtocol> *x;
99     @synchronized (x) /* Ok */
100     { dummy++; }
101   }
103   {
104     MyObjectPtrTypedef x;
105     @synchronized (x) /* Ok */
106     { dummy++; }
107   }
109   {
110     Class x;
111     @synchronized (x) /* Ok */
112     { dummy++; }
113   }
115   @synchronized (1) /* { dg-error ".@synchronized. argument is not an object" } */
116     { dummy++; }
118   @synchronized ("Test") /* { dg-error ".@synchronized. argument is not an object" } */
119     { dummy++; }
121   @synchronized () /* { dg-error "expected expression" } */
122     { dummy++; }
124   @synchronized (int) /* { dg-error "expected expression" } */
125     { dummy++; }
127   return dummy;