Debian Codegraph @

gcc/testsuite/obj-c++.dg/property/fsf-property-method-access.mm

raw
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" } { "" } } */
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 extern int printf (const char *fmt,...);
10 extern void abort (void);
11
12 #include <objc/objc.h>
13 #include <objc/runtime.h>
14
15 #ifdef __cplusplus
16 }
17 #endif
18
19 @interface Bar
20 {
21 @public
22 Class isa;
23 int FooBar;
24 }
25 + (id) initialize;
26 + (id) alloc ;
27 - (id) init;
28
29 - (int) lookAtProperty;
30 - (void) setProperty: (int) v;
31
32 @property int FooBar;
33 @end
34
35 @implementation Bar
36
37 +initialize { return self;}
38 + (id) alloc { return class_createInstance(self, 0);}
39
40 - (id) init {return self;}
41
42 @synthesize FooBar;
43
44 - (int) lookAtProperty { return FooBar; }
45 - (void) setProperty: (int) v { FooBar = v; }
46
47 @end
48
49 int main(int argc, char *argv[]) {
50 int res;
51 Bar *f = [[Bar alloc] init];
52
53 /* First, establish that the property getter & setter have been synthesized
54 and operate correctly. */
55 [f setProperty:11];
56
57 if (f.FooBar != 11)
58 { printf ("setProperty did not set FooBar\n"); abort ();}
59
60 res = [f lookAtProperty];
61 if (res != 11 )
62 { printf ("[f lookAtProperty] = %d\n", res); abort ();}
63
64 /* Make sure we haven't messed up the shortcut form. */
65 /* read ... */
66 res = f.FooBar;
67 if (res != 11 )
68 { printf ("f.FooBar = %d\n", res); abort ();}
69
70 /* ... write. */
71 f.FooBar = 0;
72 /* printf ("seems OK\n", res); */
73 return f.FooBar;
74 }
75