Daily bump.
[official-gcc.git] / gcc / testsuite / obj-c++.dg / sync-3.mm
blob2949d6a8a1358f5d2718fd184b88045d1fbd6f93
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
4 // { dg-additional-options "-Wno-objc-root-class" }
6 /* Test that the compiler is checking the argument of @synchronized(),
7    and produce errors when invalid types are used.  */
9 #include <objc/objc.h>
11 @interface MyObject
13   Class isa;
15 @end
17 @implementation MyObject
18 @end
20 @protocol MyProtocol;
22 typedef MyObject MyObjectTypedef;
23 typedef MyObject *MyObjectPtrTypedef;
24 typedef int intTypedef;
26 typedef struct { float x; float y; } point, *point_ptr;
28 int test (id object)
30   int dummy = 0;
32   {
33     int x;
34     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
35     { dummy++; }
36   }
38   {
39     intTypedef x;
40     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
41     { dummy++; }
42   }
44   {
45     int *x;
46     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
47     { dummy++; }
48   }
50   {
51     point x;
52     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
53     { dummy++; }
54   }
56   {
57     point_ptr x;
58     @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
59     { dummy++; }
60   }
62   {
63     id x;
64     @synchronized (x) /* Ok */
65     { dummy++; }
66   }
68   {
69     id <MyProtocol> x;
70     @synchronized (x) /* Ok */
71     { dummy++; }
72   }
74   {
75     MyObject *x;
76     @synchronized (x) /* Ok */
77     { dummy++; }
78   }
80   {
81     MyObject <MyProtocol> *x;
82     @synchronized (x) /* Ok */
83     { dummy++; }
84   }
86   {
87     static MyObject *x;
88     @synchronized (x) /* Ok */
89     { dummy++; }
90   }
92   {
93     MyObjectTypedef *x;
94     @synchronized (x) /* Ok */
95     { dummy++; }
96   }
98   {
99     MyObjectTypedef <MyProtocol> *x;
100     @synchronized (x) /* Ok */
101     { dummy++; }
102   }
104   {
105     MyObjectPtrTypedef x;
106     @synchronized (x) /* Ok */
107     { dummy++; }
108   }
110   {
111     Class x;
112     @synchronized (x) /* Ok */
113     { dummy++; }
114   }
116   @synchronized (1) /* { dg-error ".@synchronized. argument is not an object" } */
117     { dummy++; }
119   @synchronized ("Test") /* { dg-error ".@synchronized. argument is not an object" } */
120     { dummy++; }
122   @synchronized () /* { dg-error "expected" } */
123     { dummy++; }
125   @synchronized (int) /* { dg-error "expected" } */
126     { dummy++; }
128   return dummy;