| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
|
| 4 |
/* Test errors with the dot-syntax with pre/post increment and decrement. */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <objc/objc.h> |
| 8 |
#include <objc/runtime.h> |
| 9 |
|
| 10 |
@interface MyRootClass |
| 11 |
{ |
| 12 |
Class isa; |
| 13 |
int count; |
| 14 |
int a; |
| 15 |
} |
| 16 |
+ (id) initialize; |
| 17 |
+ (id) alloc; |
| 18 |
- (id) init; |
| 19 |
@property (assign, readonly) int count; |
| 20 |
- (void) setWriteOnlyCount: (int)value; |
| 21 |
@end |
| 22 |
|
| 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 |
| 29 |
{ |
| 30 |
a = value; |
| 31 |
} |
| 32 |
@end |
| 33 |
|
| 34 |
int main (void) |
| 35 |
{ |
| 36 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 37 |
|
| 38 |
object.count = 10; /* { dg-error "'readonly' property cannot be set" } */ |
| 39 |
if (object.count != 10) /* Ok */ |
| 40 |
abort (); |
| 41 |
|
| 42 |
/* Test errors when trying to change a readonly property using |
| 43 |
pre/post increment/decrement operators. */ |
| 44 |
object.count++; /* { dg-error "'readonly' property cannot be set" } */ |
| 45 |
|
| 46 |
++object.count; /* { dg-error "'readonly' property cannot be set" } */ |
| 47 |
|
| 48 |
object.count--; /* { dg-error "'readonly' property cannot be set" } */ |
| 49 |
|
| 50 |
--object.count; /* { dg-error "'readonly' property cannot be set" } */ |
| 51 |
|
| 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 */ |
| 55 |
|
| 56 |
object.writeOnlyCount++; /* { dg-error "no .writeOnlyCount. getter found" } */ |
| 57 |
|
| 58 |
++object.writeOnlyCount; /* { dg-error "no .writeOnlyCount. getter found" } */ |
| 59 |
|
| 60 |
object.writeOnlyCount--; /* { dg-error "no .writeOnlyCount. getter found" } */ |
| 61 |
|
| 62 |
--object.writeOnlyCount; /* { dg-error "no .writeOnlyCount. getter found" } */ |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
|