Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc.dg / property / at-property-10.m
blob79d2ecdbbf0354bdf06ddc81cfc1362d61365dee
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test the property syntax in a number of expressions.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
14   int a;
16 /* Use the simplest synthesized accessor (assign, nonatomic) as we are
17    not testing the synthesized accessors in this test, just the
18    property syntax.  */
19 @property (nonatomic) int a;
20 + (id) initialize;
21 + (id) alloc;
22 - (id) init;
23 @end
25 @implementation MyRootClass
26 + (id) initialize { return self; }
27 + (id) alloc { return class_createInstance (self, 0); }
28 - (id) init { return self; }
29 @synthesize a;
30 @end
32 int
33 test (int g)
35   return g;
38 int main (void)
40   MyRootClass *object = [[MyRootClass alloc] init];
41   MyRootClass *object2 = [[MyRootClass alloc] init];
43   object.a = 14;
44   object.a = object.a + object.a;
46   if (object.a != 28)
47     abort ();
49   object.a = 99;
50   object.a++;
52   if (object.a != 100)
53     abort ();
55   object.a = 99;
56   object.a *= 2;
58   if (object.a != 198)
59     abort ();
61   {
62     int f = object.a;
64     if (f != 198)
65       abort ();
67     if (f != object.a)
68       abort ();
70     if (object.a != f)
71       abort ();
73     object.a = object.a;
75     if (object.a != 198)
76       abort ();
77   }  
79   if (test (object.a) != 198)
80     abort ();
82   object.a = -object.a;
84   if (object.a != -198)
85     abort ();
87   for (object.a = 0; object.a < 99; object.a++)
88     object2.a = object.a;
90   if (object2.a != object.a - 1)
91     abort ();
93   if (object2.a != 98)
94     abort ();
96   if (object.a != 99)
97     abort ();
99   return 0;