Merged r157653 through r157895 into branch.
[official-gcc.git] / gcc / testsuite / objc / execute / class_self-2.m
blobad2b76b50e8d175281f997af0f27abde4c731bce
1 /* Contributed by Nicola Pero - Fri Oct 26 22:39:32 BST 2001 */
2 #include <stdlib.h>
3 #include <objc/objc.h>
5 /* Test calling a class method on self where self has been redefined
6    to be another class - the call requires a cast */
9 /* The first class */
10 struct d
12   int a;
15 @interface ClassA
17   Class isa;
19 + (Class) class;
20 + (struct d) method;
21 @end
23 @implementation ClassA
24 + (Class) class
26   return self;
29 + (struct d) method
31   struct d u;
32   u.a = 5;
33   
34   return u;
36 #ifdef __NEXT_RUNTIME__                                   
37 + initialize { return self; }
38 #endif
39 @end
41 /* The second class */
42 @interface TestClass
44   Class isa;
46 + (void) test;
47 @end
49 @implementation TestClass
50 + (void) test
52   self = [ClassA class];
53   
55   if ([(Class)self method].a != 5)
56     {
57       abort ();
58     }
61 #ifdef __NEXT_RUNTIME__                                   
62 + initialize { return self; }
63 #endif
64 @end
67 int main (void)
69   [TestClass test];
71   return 0;