Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc.dg / property / dotsyntax-17.m
blobc28e11f484b59747489db5ed74c359fd70d29d6a
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-do compile } */
4 /* Test errors with the dot-syntax with pre/post increment and decrement.  */
6 #include <stdlib.h>
7 #include <objc/objc.h>
8 #include <objc/runtime.h>
10 @interface MyRootClass
12   Class isa;
13   int count;
14   int a;
16 + (id) initialize;
17 + (id) alloc;
18 - (id) init;
19 @property (assign, readonly) int count;
20 - (void) setWriteOnlyCount: (int)value;
21 @end
23 @implementation MyRootClass
24 + (id) initialize { return self; }
25 + (id) alloc { return class_createInstance (self, 0); }
26 - (id) init { return self; }
27 @synthesize count;
28 - (void) setWriteOnlyCount: (int)value
30   a = value;
32 @end
34 int main (void)
36   MyRootClass *object = [[MyRootClass alloc] init];
38   object.count = 10; /* { dg-error "readonly property can not be set" } */
39   if (object.count != 10) /* Ok */
40     abort ();
42   /* Test errors when trying to change a readonly property using
43      pre/post increment/decrement operators.  */
44   object.count++; /* { dg-error "readonly property can not be set" } */
46   ++object.count; /* { dg-error "readonly property can not be set" } */
48   object.count--; /* { dg-error "readonly property can not be set" } */
50   --object.count; /* { dg-error "readonly property can not be set" } */
52   /* Test errors when trying to change something using Objective-C 2.0
53      dot-syntax but there is a setter but no getter.  */
54   object.writeOnlyCount = 10; /* Ok */
56   object.writeOnlyCount++; /* { dg-error "no .writeOnlyCount. getter found" } */
58   ++object.writeOnlyCount; /* { dg-error "no .writeOnlyCount. getter found" } */
60   object.writeOnlyCount--; /* { dg-error "no .writeOnlyCount. getter found" } */
62   --object.writeOnlyCount; /* { dg-error "no .writeOnlyCount. getter found" } */
64   return 0;