Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / objc.dg / property / fsf-property-method-access.m
blob01eea5bf75da76b29108880a8b04f93017bc76f1
1 /* test access in methods, auto-generated getter/setter based on property name.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 extern int printf (char *fmt,...) ;
6 extern void abort (void);
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface Bar
13 @public
14   Class isa;
15   int FooBar;
17 + (id) initialize;
18 + (id) alloc ;
19 - (id) init;
21 - (int) lookAtProperty;
22 - (void) setProperty: (int) v;
24 @property int FooBar;
25 @end
27 @implementation Bar
29 +initialize { return self;}
30 + (id) alloc { return class_createInstance(self, 0);}
32 - (id) init {return self;}
34 @synthesize FooBar;
36 - (int) lookAtProperty { return FooBar; }
37 - (void) setProperty: (int) v { FooBar = v; }
39 @end
41 int main(int argc, char *argv[]) {
42   int res;
43   Bar *f = [[Bar alloc] init];
45   /* First, establish that the property getter & setter have been synthesized 
46      and operate correctly.  */
47   [f setProperty:11];
49   if (f.FooBar != 11)
50     { printf ("setProperty did not set FooBar\n"); abort ();}
51       
52   res = [f lookAtProperty];    
53   if (res != 11 )
54     { printf ("[f lookAtProperty] = %d\n",  res); abort ();}
55   
56   /* Make sure we haven't messed up the shortcut form.  */
57   /* read ... */
58   res = f.FooBar;
59   if (res != 11 )
60     { printf ("f.FooBar = %d\n",  res); abort ();}
61   
62   /* ... write. */
63   f.FooBar = 0;
64   /* printf ("seems OK\n",  res); */
65   return f.FooBar;