Debian Codegraph @

gcc/testsuite/objc/execute/class_self-2.m

raw
1 /* Contributed by Nicola Pero - Fri Oct 26 22:39:32 BST 2001 */
2 #include <stdlib.h>
3 #include <objc/objc.h>
4
5 /* Test calling a class method on self where self has been redefined
6 to be another class - the call requires a cast */
7
8
9 /* The first class */
10 struct d
11 {
12 int a;
13 };
14
15 @interface ClassA
16 {
17 Class isa;
18 }
19 + (Class) class;
20 + (struct d) method;
21 @end
22
23 @implementation ClassA
24 + (Class) class
25 {
26 return self;
27 }
28
29 + (struct d) method
30 {
31 struct d u;
32 u.a = 5;
33
34 return u;
35 }
36 + initialize { return self; }
37 @end
38
39 /* The second class */
40 @interface TestClass
41 {
42 Class isa;
43 }
44 + (void) test;
45 @end
46
47 @implementation TestClass
48 + (void) test
49 {
50 self = [ClassA class];
51
52
53 if ([(Class)self method].a != 5)
54 {
55 abort ();
56 }
57 }
58
59 + initialize { return self; }
60 @end
61
62
63 int main (void)
64 {
65 [TestClass test];
66
67 return 0;
68 }