1 /* Check if casting 'self' or 'super' affects message lookup in the correct way. */
2 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
3 /* { dg-do compile } */
5 #include "../objc-obj-c++-shared/TestsuiteObject.h"
6 #include "../objc-obj-c++-shared/runtime.h"
9 /* FIXME: This is temporary. At the moment, the compiler, when
10 compiling for the GNU runtime and doing method checks, only
11 recognizes objc_get_class(), and not objc_getClass(). So
12 temporarily force objc_get_class() to be used. */
13 #ifndef __NEXT_RUNTIME__
14 # define objc_getClass(C) objc_get_class(C)
19 - (int) instance_func0;
22 @interface Derived: TestsuiteObject
30 - (int) instance_func1;
31 - (int) instance_func2;
32 - (int) instance_func3;
33 - (int) instance_func4;
34 - (int) instance_func5;
35 - (int) instance_func6;
36 - (int) instance_func7;
39 @interface Derived (Categ)
40 + (int) categ_class_func1;
41 + (int) categ_class_func2;
42 - (int) categ_instance_func1;
43 - (int) categ_instance_func2;
46 @implementation Derived
49 int i = (size_t)[self class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
50 return i + (size_t)[super class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
54 int i = [(id <Func>)self class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
55 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
56 i += [(Class <Func>)self class_func0];
57 return i + [(Class <Func>)super class_func0];
61 return [(TestsuiteObject <Func> *)super class_func0];
65 return [(Derived <Func> *)super class_func0];
69 int i = (size_t)[Derived class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
70 return i + (size_t)[TestsuiteObject class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
74 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
78 return [objc_getClass("Derived") class_func1];
80 - (int) instance_func1
82 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
83 return i + (size_t)[super instance_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
85 - (int) instance_func2
87 return [(id <Func>)super instance_func0];
89 - (int) instance_func3
91 return [(TestsuiteObject <Func> *)super instance_func0];
93 - (int) instance_func4
95 return [(Derived <Func> *)super instance_func0];
97 - (int) instance_func5
99 int i = (size_t)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
100 return i + (size_t)[TestsuiteObject instance_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+instance_func1." } */
102 - (int) instance_func6
104 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
106 - (int) instance_func7
108 return [objc_getClass("Derived") class_func1];
112 @implementation Derived (Categ)
113 + (int) categ_class_func1
115 int i = (size_t)[self class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
116 i += [self class_func1];
117 i += [self categ_class_func2];
118 i += (size_t)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
119 return i + (size_t)[super class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
121 + (int) categ_class_func2
123 int i = [(id <Func>)self class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
124 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
125 i += [(Class <Func>)self class_func0];
126 return i + [(Class <Func>)super class_func0];
128 - (int) categ_instance_func1
130 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
131 i += [(Derived <Func> *)self categ_instance_func2];
132 i += (size_t)[(TestsuiteObject <Func> *)self categ_instance_func2]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-categ_instance_func2." } */
133 /* { dg-warning ".\\-categ_instance_func2. not found in protocol" "" { target *-*-* } .-1 } */
134 i += (size_t)[(id <Func>)self categ_instance_func2]; /* { dg-warning ".\\-categ_instance_func2. not found in protocol" } */
135 i += [(id)self categ_instance_func2];
136 return i + (size_t)[super instance_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
138 - (int) categ_instance_func2
140 return [(id <Func>)super instance_func0];
144 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
145 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
146 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */