Create embedded-5_0-branch branch for development on ARM embedded cores.
[official-gcc.git] / embedded-5_0-branch / gcc / testsuite / obj-c++.dg / property / dotsyntax-18.mm
blob5697d311d27b24e3f084352eb28cc2ca92c5e522
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 tricky assignments.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
14   int a;
16 + (id) initialize;
17 + (id) alloc;
18 - (id) init;
19 - (int) count;
20 - (void) setCount: (int)count;
21 - (int) somethingToExecuteOnlyOnce;
22 @end
24 @implementation MyRootClass
25 + (id) initialize { return self; }
26 + (id) alloc { return class_createInstance (self, 0); }
27 - (id) init { return self; }
28 - (int) count
30   return a;
32 - (void) setCount: (int)count
34   a = count;
36 - (int) somethingToExecuteOnlyOnce
38   a++;
39   return 10;
41 @end
43 int main (void)
45   MyRootClass *object1 = [[MyRootClass alloc] init];
46   MyRootClass *object2 = [[MyRootClass alloc] init];
47   MyRootClass *object3 = [[MyRootClass alloc] init];
48   int i;
50   object1.count = 10;
51   if (object1.count != 10)
52     abort ();
54   object2.count = 10;
55   if (object2.count != 10)
56     abort ();
58   /* Test multiple assignments to a constant.  */
59   object1.count = object2.count = 20;
61   if (object1.count != 20 || object2.count != 20)
62     abort ();
64   i = object1.count = 30;
66   if (i != 30 || object1.count != 30)
67     abort ();
69   i = object2.count = 30;
71   if (i != 30 || object2.count != 30)
72     abort ();
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);
78   if (object1.count != 30 || object2.count != 31)
79     abort ();
81   /* Test multiple assignments with side effects.  */
82   object3.count = object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
84   if (object1.count != 30 || object2.count != 32 || object3.count != 30)
85     abort ();
87   return 0;