Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / objc.dg / property / dotsyntax-19.m
blobdf4867b0ad3eb5c10aa7f944234b6d3112472526
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test dot-syntax with more tricky assignments.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
14   id a;
15   id b;
16   int p1;
17   float p2;
19 + (id) initialize;
20 + (id) alloc;
21 - (id) init;
23 @property (assign) id object1;
24 @property (assign) id object2;
25 - (id) test;
26 - (id) myself;
27 - (id) nilObject;
29 @property int p1;
30 @property float p2;
31 @end
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
41   /* Test multiple assignments with 'self'.  */
42   self.object1 = self.object2 = self;
44   if (self.object1 != self || self.object2 != self)
45     abort ();
47   /* Test multiple assignments with a conditional and method calls.  */
48   self.object1 = self.object2 = (self ? [self myself] : [self nilObject]);
50   if (self.object1 != self || self.object2 != self)
51     abort ();
53   self.object1 = self.object2 = (self ? [self nilObject] : [self myself]);
55   if (self.object1 != nil || self.object2 != nil)
56     abort ();
58   return self.object1;
60 - (id) myself
62   return self;
64 - (id) nilObject
66   return nil;
69 @synthesize p1;
70 @synthesize p2;
71 @end
73 int main (void)
75   MyRootClass *object = [[MyRootClass alloc] init];
76   MyRootClass *object1 = [[MyRootClass alloc] init];
78   [object test];
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;
86   if (object.p1 != 12 || object.p2 != 12)
87     abort ();
89   object.p1 = object.p2 = 2.7;
91   if (object.p1 != 2)
92     abort ();
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     }
104   if (object.p1 != 0 || object1.p1 != 0)
105     abort ();
107   if ((object.p1 = 0))
108     abort ();
110   return 0;