]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm
c-decl.c (start_decl): Adjust quoting and hyphenation in diagnostics.
[thirdparty/gcc.git] / gcc / testsuite / obj-c++.dg / property / dotsyntax-17.mm
CommitLineData
925e8657
NP
1/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, 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
34int main (void)
35{
36 MyRootClass *object = [[MyRootClass alloc] init];
925e8657 37
0ecf545c 38 object.count = 10; /* { dg-error "'readonly' property cannot be set" } */
925e8657
NP
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. */
0ecf545c 44 object.count++; /* { dg-error "'readonly' property cannot be set" } */
925e8657 45
0ecf545c 46 ++object.count; /* { dg-error "'readonly' property cannot be set" } */
925e8657 47
0ecf545c 48 object.count--; /* { dg-error "'readonly' property cannot be set" } */
925e8657 49
0ecf545c 50 --object.count; /* { dg-error "'readonly' property cannot be set" } */
925e8657
NP
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