Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc.dg / property / synthesize-7.m
blob929e3803bf95215853eb29e481e1f8e0003104cc
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 @synthesize with protocols of protocols.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @protocol ProtocolA
12 @property int countA;
13 @end
15 @protocol ProtocolB <ProtocolA>
16 @property int countB;
17 @end
19 @protocol ProtocolC <ProtocolB>
20 @property int countC;
21 @end
23 @protocol ProtocolD
24 @property int countD;
25 @end
27 @interface MyRootClass <ProtocolC>
29   Class isa;
30   int countA;
31   int countB;
32   int countC;
34 + (id) initialize;
35 + (id) alloc;
36 - (id) init;
37 @end
39 @implementation MyRootClass
40 + (id) initialize { return self; }
41 + (id) alloc { return class_createInstance (self, 0); }
42 - (id) init { return self; }
43 @synthesize countA;
44 @synthesize countB;
45 @synthesize countC;
46 @end
48 @interface MySubClass : MyRootClass <ProtocolD>
50   int countD;
52 @end
54 @implementation MySubClass
55 @synthesize countD;
56 @end
58 int main (void)
60   MySubClass *object = [[MySubClass alloc] init];
61   int i;
63   for (i = 0; i < 10; i++)
64     {
65       object.countA += i;
66       object.countB += i + 1;
67       object.countC += i + 2;
68       object.countD += i + 3;
69     }
71   if (object.countA != 45)
72     abort ();
74   if (object.countB != 55)
75     abort ();
77   if (object.countC != 65)
78     abort ();
80   if (object.countD != 75)
81     abort ();
83   return 0;