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. */
8 #include <objc/runtime.h>
10 @interface MyRootClass
19 @property (assign, readonly) int count;
20 - (void) setWriteOnlyCount: (int)value;
23 @implementation MyRootClass
24 + (id) initialize { return self; }
25 + (id) alloc { return class_createInstance (self, 0); }
26 - (id) init { return self; }
28 - (void) setWriteOnlyCount: (int)value
36 MyRootClass *object = [[MyRootClass alloc] init];
38 object.count = 10; /* { dg-error "readonly property can not be set" } */
39 if (object.count != 10) /* Ok */
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" } */