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 /* NOTE: we are relying on the built-in type for objc_getClass being used
7 rather than the one that might come from including <objc/runtime.h>. */
10 /* FIXME: This is temporary. At the moment, the compiler, when
11 compiling for the GNU runtime and doing method checks, only
12 recognizes objc_get_class(), and not objc_getClass(). So
13 temporarily force objc_get_class() to be used. */
14 #ifndef __NEXT_RUNTIME__
15 # define objc_getClass(C) objc_get_class(C)
18 /* FIXME: casting of super is not permitted by clang, so that many of the
19 tests here are testing non-portable code. */
23 - (int) instance_func0;
26 @interface Derived: TestsuiteObject
34 - (int) instance_func1;
35 - (int) instance_func2;
36 - (int) instance_func3;
37 - (int) instance_func4;
38 - (int) instance_func5;
39 - (int) instance_func6;
40 - (int) instance_func7;
43 @interface Derived (Categ)
44 + (int) categ_class_func1;
45 + (int) categ_class_func2;
46 - (int) categ_instance_func1;
47 - (int) categ_instance_func2;
50 @implementation Derived
53 int i = (size_t)[self class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
54 return i + (size_t)[super class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
58 int i = [(id <Func>)self class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
59 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
60 i += [(Class <Func>)self class_func0];
61 return i + [(Class <Func>)super class_func0];
65 return [(TestsuiteObject <Func> *)super class_func0];
69 return [(Derived <Func> *)super class_func0];
73 int i = (size_t)[Derived class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
74 return i + (size_t)[TestsuiteObject class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
78 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
82 return [objc_getClass("Derived") class_func1];
84 - (int) instance_func1
86 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
87 return i + (size_t)[super instance_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
89 - (int) instance_func2
91 return [(id <Func>)super instance_func0];
93 - (int) instance_func3
95 return [(TestsuiteObject <Func> *)super instance_func0];
97 - (int) instance_func4
99 return [(Derived <Func> *)super instance_func0];
101 - (int) instance_func5
103 int i = (size_t)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
104 return i + (size_t)[TestsuiteObject instance_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+instance_func1." } */
106 - (int) instance_func6
108 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
110 - (int) instance_func7
112 return [objc_getClass("Derived") class_func1];
116 @implementation Derived (Categ)
117 + (int) categ_class_func1
119 int i = (size_t)[self class_func0]; /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
120 i += [self class_func1];
121 i += [self categ_class_func2];
122 i += (size_t)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
123 return i + (size_t)[super class_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
125 + (int) categ_class_func2
127 int i = [(id <Func>)self class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
128 i += [(id <Func>)super class_func0]; /* { dg-warning ".\\-class_func0. not found in protocol" } */
129 i += [(Class <Func>)self class_func0];
130 return i + [(Class <Func>)super class_func0];
132 - (int) categ_instance_func1
134 int i = (size_t)[self instance_func0]; /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
135 i += [(Derived <Func> *)self categ_instance_func2];
136 i += (size_t)[(TestsuiteObject <Func> *)self categ_instance_func2]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-categ_instance_func2." } */
137 /* { dg-warning ".\\-categ_instance_func2. not found in protocol" "" { target *-*-* } .-1 } */
138 i += (size_t)[(id <Func>)self categ_instance_func2]; /* { dg-warning ".\\-categ_instance_func2. not found in protocol" } */
139 i += [(id)self categ_instance_func2];
140 return i + (size_t)[super instance_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
142 - (int) categ_instance_func2
144 return [(id <Func>)super instance_func0];
148 /* { dg-warning "messages without a matching method signature will be assumed to return .id. and accept .\.\.\.. as arguments" "" { target *-*-* } 0 } */