Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / obj-c++.dg / property / synthesize-3.mm
blob8669905316a119be7ed6dfce7b8e2f585cb335d3
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 for a @property which is not declared directly in
6    the @interface, but in a @protocol that the @interface conforms
7    to.  */
9 #include <objc/objc.h>
10 #include <objc/runtime.h>
11 #include <stdlib.h>
13 @interface MyRootClass
15   Class isa;
17 + (id) initialize;
18 + (id) alloc;
19 - (id) init;
20 @end
22 @implementation MyRootClass
23 + (id) initialize { return self; }
24 + (id) alloc { return class_createInstance (self, 0); }
25 - (id) init { return self; }
26 @end
28 @protocol MyProtocol
29 @property int v1;
30 @end
32 @protocol MyProtocol2
33 @property int v2;
34 @end
36 @interface Test : MyRootClass <MyProtocol, MyProtocol2>
38   int v1;
39   int _v2;
41 @end
43 @implementation Test
44 @synthesize v1;
45 @synthesize v2 = _v2;
46 @end
48 int main (void)
50   Test *object = [[Test alloc] init];
52   /* Check that the synthesized methods exist and work.  Do not invoke
53      them via property syntax - that is another test.  Here we just
54      want to test the synthesis of the methods.  */
55   [object setV1: 400];
57   if ([object v1] != 400)
58     abort ();
60   [object setV2: 31];
62   if ([object v2] != 31)
63     abort ();
65   return 0;