Debian Codegraph @

gcc/testsuite/objc.dg/property/dotsyntax-19.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 more 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 id a;
15 id b;
16 int p1;
17 float p2;
18 }
19 + (id) initialize;
20 + (id) alloc;
21 - (id) init;
22
23 @property (assign) id object1;
24 @property (assign) id object2;
25 - (id) test;
26 - (id) myself;
27 - (id) nilObject;
28
29 @property int p1;
30 @property float p2;
31 @end
32
33 @implementation MyRootClass
34 + (id) initialize { return self; }
35 + (id) alloc { return class_createInstance (self, 0); }
36 - (id) init { return self; }
37 @synthesize object1 = a;
38 @synthesize object2 = b;
39 - (id) test
40 {
41 /* Test multiple assignments with 'self'. */
42 self.object1 = self.object2 = self;
43
44 if (self.object1 != self || self.object2 != self)
45 abort ();
46
47 /* Test multiple assignments with a conditional and method calls. */
48 self.object1 = self.object2 = (self ? [self myself] : [self nilObject]);
49
50 if (self.object1 != self || self.object2 != self)
51 abort ();
52
53 self.object1 = self.object2 = (self ? [self nilObject] : [self myself]);
54
55 if (self.object1 != nil || self.object2 != nil)
56 abort ();
57
58 return self.object1;
59 }
60 - (id) myself
61 {
62 return self;
63 }
64 - (id) nilObject
65 {
66 return nil;
67 }
68
69 @synthesize p1;
70 @synthesize p2;
71 @end
72
73 int main (void)
74 {
75 MyRootClass *object = [[MyRootClass alloc] init];
76 MyRootClass *object1 = [[MyRootClass alloc] init];
77
78 [object test];
79
80 /* Now, test multiple assignments with different types. Use
81 int/float as they seem to happily crash the compiler in gimplify
82 if proper conversions are not being generated by the
83 frontend. ;-) */
84 object.p1 = object.p2 = 12;
85
86 if (object.p1 != 12 || object.p2 != 12)
87 abort ();
88
89 object.p1 = object.p2 = 2.7;
90
91 if (object.p1 != 2)
92 abort ();
93
94 /* Just try a different loop, mixing in a few different standard C
95 constructs to cover a few other cases. */
96 object.p1 = 10;
97 object1.p1 = 0;
98 while (object.p1)
99 {
100 object1.p1 += ((object.p2 = 4.56) ? 0 : object.p1);
101 object.p1--;
102 }
103
104 if (object.p1 != 0 || object1.p1 != 0)
105 abort ();
106
107 if ((object.p1 = 0))
108 abort ();
109
110 return 0;
111 }
112
113