2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc.dg / call-super-2.m
blobcd7db41bffe728e247222ea89622d1d397eda77c
1 /* Check if casting 'self' or 'super' affects message lookup in the
2    correct way.  */
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
4 /* { dg-do compile } */
6 #include <objc/objc.h>
7 #include <objc/Object.h>
9 #ifdef __NEXT_RUNTIME__
10 #define OBJC_GETCLASS objc_getClass
11 #else
12 #define OBJC_GETCLASS objc_get_class
13 #endif
15 @protocol Func
16 + (int) class_func0;
17 - (int) instance_func0;
18 @end
20 @interface Derived: Object
21 + (int) class_func1;
22 + (int) class_func2;
23 + (int) class_func3;
24 + (int) class_func4;
25 + (int) class_func5;
26 + (int) class_func6;
27 + (int) class_func7;
28 - (int) instance_func1;
29 - (int) instance_func2;
30 - (int) instance_func3;
31 - (int) instance_func4;
32 - (int) instance_func5;
33 - (int) instance_func6;
34 - (int) instance_func7;
35 @end
37 @interface Derived (Categ)
38 + (int) categ_class_func1;
39 + (int) categ_class_func2;
40 - (int) categ_instance_func1;
41 - (int) categ_instance_func2;
42 @end
44 @implementation Derived
45 + (int) class_func1
47    int i = (int)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
48        /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 47 } */
49        /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 47 } */
50        /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 47 } */
51    return i + (int)[super class_func0];   /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
53 + (int) class_func2
55    int i = [(id <Func>)self class_func0];
56    return i + [(id <Func>)super class_func0];
58 + (int) class_func3
60    return [(Object <Func> *)super class_func0];
62 + (int) class_func4
64    return [(Derived <Func> *)super class_func0];
65 }   
66 + (int) class_func5
68    int i = (int)[Derived class_func0];    /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
69    return i + (int)[Object class_func0];  /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
71 + (int) class_func6
73    return (int)[OBJC_GETCLASS("Object") class_func1];  /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
75 + (int) class_func7
77    return [OBJC_GETCLASS("Derived") class_func1];
79 - (int) instance_func1
81    int i = (int)[self instance_func0];     /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
82    return i + (int)[super instance_func0]; /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
84 - (int) instance_func2
86    return [(id <Func>)super instance_func0];
88 - (int) instance_func3
90    return [(Object <Func> *)super instance_func0];
92 - (int) instance_func4
94    return [(Derived <Func> *)super instance_func0];
95 }   
96 - (int) instance_func5
98    int i = (int)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
99    return i + (int)[Object instance_func1]; /* { dg-warning ".Object. may not respond to .\\+instance_func1." } */
101 - (int) instance_func6
103    return (int)[OBJC_GETCLASS("Object") class_func1]; /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
105 - (int) instance_func7
107    return [OBJC_GETCLASS("Derived") class_func1];
109 @end
111 @implementation Derived (Categ)
112 + (int) categ_class_func1
114    int i = (int)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
115    i += [self class_func1];
116    i += [self categ_class_func2];
117    i += (int)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
118    return i + (int)[super class_func0];   /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
120 + (int) categ_class_func2
122    int i = [(id <Func>)self class_func0];
123    return i + [(id <Func>)super class_func0];
125 - (int) categ_instance_func1
127    int i = (int)[self instance_func0];    /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
128    i += [(Derived <Func> *)self categ_instance_func2];
129    i += (int)[(Object <Func> *)self categ_instance_func2]; /* { dg-warning ".Object. may not respond to .\\-categ_instance_func2." } */
130    /* { dg-warning ".\\-categ_instance_func2. not implemented by protocol" "" { target *-*-* } 129 } */
131    i += (int)[(id <Func>)self categ_instance_func2];  /* { dg-warning ".\\-categ_instance_func2. not implemented by protocol" } */
132    i += [(id)self categ_instance_func2];
133    return i + (int)[super instance_func0];   /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
135 - (int) categ_instance_func2
137    return [(id <Func>)super instance_func0];
139 @end