Debian Codegraph @

gcc/testsuite/objc.dg/property/dotsyntax-18.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, November 2010. */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
5 /* Test dot-syntax with tricky assignments. */
6
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
10
11 @interface MyRootClass
12 {
13 Class isa;
14 int a;
15 }
16 + (id) initialize;
17 + (id) alloc;
18 - (id) init;
19 - (int) count;
20 - (void) setCount: (int)count;
21 - (int) somethingToExecuteOnlyOnce;
22 @end
23
24 @implementation MyRootClass
25 + (id) initialize { return self; }
26 + (id) alloc { return class_createInstance (self, 0); }
27 - (id) init { return self; }
28 - (int) count
29 {
30 return a;
31 }
32 - (void) setCount: (int)count
33 {
34 a = count;
35 }
36 - (int) somethingToExecuteOnlyOnce
37 {
38 a++;
39 return 10;
40 }
41 @end
42
43 int main (void)
44 {
45 MyRootClass *object1 = [[MyRootClass alloc] init];
46 MyRootClass *object2 = [[MyRootClass alloc] init];
47 MyRootClass *object3 = [[MyRootClass alloc] init];
48 int i;
49
50 object1.count = 10;
51 if (object1.count != 10)
52 abort ();
53
54 object2.count = 10;
55 if (object2.count != 10)
56 abort ();
57
58 /* Test multiple assignments to a constant. */
59 object1.count = object2.count = 20;
60
61 if (object1.count != 20 || object2.count != 20)
62 abort ();
63
64 i = object1.count = 30;
65
66 if (i != 30 || object1.count != 30)
67 abort ();
68
69 i = object2.count = 30;
70
71 if (i != 30 || object2.count != 30)
72 abort ();
73
74 /* Test a simple assignment to something with a side-effect; the
75 'rhs' should be evaluated only once. */
76 object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
77
78 if (object1.count != 30 || object2.count != 31)
79 abort ();
80
81 /* Test multiple assignments with side effects. */
82 object3.count = object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
83
84 if (object1.count != 30 || object2.count != 32 || object3.count != 30)
85 abort ();
86
87 return 0;
88 }
89
90