1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test dot-syntax with tricky assignments. */
9 #include <objc/runtime.h>
11 @interface MyRootClass
20 - (void) setCount: (int)count;
21 - (int) somethingToExecuteOnlyOnce;
24 @implementation MyRootClass
25 + (id) initialize { return self; }
26 + (id) alloc { return class_createInstance (self, 0); }
27 - (id) init { return self; }
32 - (void) setCount: (int)count
36 - (int) somethingToExecuteOnlyOnce
45 MyRootClass *object1 = [[MyRootClass alloc] init];
46 MyRootClass *object2 = [[MyRootClass alloc] init];
47 MyRootClass *object3 = [[MyRootClass alloc] init];
51 if (object1.count != 10)
55 if (object2.count != 10)
58 /* Test multiple assignments to a constant. */
59 object1.count = object2.count = 20;
61 if (object1.count != 20 || object2.count != 20)
64 i = object1.count = 30;
66 if (i != 30 || object1.count != 30)
69 i = object2.count = 30;
71 if (i != 30 || object2.count != 30)
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)
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)