1 /* Check if casting 'self' or 'super' affects message lookup in the
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
4 /* { dg-do compile } */
8 #include <objc/Object.h>
10 #ifdef __NEXT_RUNTIME__
11 #define OBJC_GETCLASS objc_getClass
13 #define OBJC_GETCLASS objc_get_class
18 - (int) instance_func0;
21 @interface Derived: Object
29 - (int) instance_func1;
30 - (int) instance_func2;
31 - (int) instance_func3;
32 - (int) instance_func4;
33 - (int) instance_func5;
34 - (int) instance_func6;
35 - (int) instance_func7;
38 @interface Derived (Categ)
39 + (int) categ_class_func1;
40 + (int) categ_class_func2;
41 - (int) categ_instance_func1;
42 - (int) categ_instance_func2;
45 @implementation Derived
48 int i = (size_t)[self class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
49 return i + (size_t)[super class_func0]; /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
53 int i = [(id <Func>)self class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
54 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
55 i += [(Class <Func>)self class_func0];
56 return i + [(Class <Func>)super class_func0];
60 return [(Object <Func> *)super class_func0];
64 return [(Derived <Func> *)super class_func0];
68 int i = (size_t)[Derived class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
69 return i + (size_t)[Object class_func0]; /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
73 return (size_t)[OBJC_GETCLASS("Object") class_func1]; /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
77 return [OBJC_GETCLASS("Derived") class_func1];
79 - (int) instance_func1
81 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
82 return i + (size_t)[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];
96 - (int) instance_func5
98 int i = (size_t)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
99 return i + (size_t)[Object instance_func1]; /* { dg-warning ".Object. may not respond to .\\+instance_func1." } */
101 - (int) instance_func6
103 return (size_t)[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];
111 @implementation Derived (Categ)
112 + (int) categ_class_func1
114 int i = (size_t)[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 += (size_t)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
118 return i + (size_t)[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]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
123 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
124 i += [(Class <Func>)self class_func0];
125 return i + [(Class <Func>)super class_func0];
127 - (int) categ_instance_func1
129 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
130 i += [(Derived <Func> *)self categ_instance_func2];
131 i += (size_t)[(Object <Func> *)self categ_instance_func2]; /* { dg-warning ".Object. may not respond to .\\-categ_instance_func2." } */
132 /* { dg-warning ".\\-categ_instance_func2. not found in protocol" "" { target *-*-* } 131 } */
133 i += (size_t)[(id <Func>)self categ_instance_func2]; /* { dg-warning ".\\-categ_instance_func2. not found in protocol" } */
134 i += [(id)self categ_instance_func2];
135 return i + (size_t)[super instance_func0]; /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
137 - (int) categ_instance_func2
139 return [(id <Func>)super instance_func0];
143 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
144 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
145 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */