Debian Codegraph @

gcc/testsuite/objc.dg/call-super-2.m

raw
1 /* Check if casting 'self' or 'super' affects message lookup in the correct way. */
2 /* Contributed by Ziemowit Laski <[email protected]>. */
3 /* { dg-do compile } */
4
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>. */
8 #include <stddef.h>
9
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)
16 #endif
17
18 /* FIXME: casting of super is not permitted by clang, so that many of the
19 tests here are testing non-portable code. */
20
21 @protocol Func
22 + (int) class_func0;
23 - (int) instance_func0;
24 @end
25
26 @interface Derived: TestsuiteObject
27 + (int) class_func1;
28 + (int) class_func2;
29 + (int) class_func3;
30 + (int) class_func4;
31 + (int) class_func5;
32 + (int) class_func6;
33 + (int) class_func7;
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;
41 @end
42
43 @interface Derived (Categ)
44 + (int) categ_class_func1;
45 + (int) categ_class_func2;
46 - (int) categ_instance_func1;
47 - (int) categ_instance_func2;
48 @end
49
50 @implementation Derived
51 + (int) class_func1
52 {
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." } */
55 }
56 + (int) class_func2
57 {
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];
62 }
63 + (int) class_func3
64 {
65 return [(TestsuiteObject <Func> *)super class_func0];
66 }
67 + (int) class_func4
68 {
69 return [(Derived <Func> *)super class_func0];
70 }
71 + (int) class_func5
72 {
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." } */
75 }
76 + (int) class_func6
77 {
78 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
79 }
80 + (int) class_func7
81 {
82 return [objc_getClass("Derived") class_func1];
83 }
84 - (int) instance_func1
85 {
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." } */
88 }
89 - (int) instance_func2
90 {
91 return [(id <Func>)super instance_func0];
92 }
93 - (int) instance_func3
94 {
95 return [(TestsuiteObject <Func> *)super instance_func0];
96 }
97 - (int) instance_func4
98 {
99 return [(Derived <Func> *)super instance_func0];
100 }
101 - (int) instance_func5
102 {
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." } */
105 }
106 - (int) instance_func6
107 {
108 return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
109 }
110 - (int) instance_func7
111 {
112 return [objc_getClass("Derived") class_func1];
113 }
114 @end
115
116 @implementation Derived (Categ)
117 + (int) categ_class_func1
118 {
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." } */
124 }
125 + (int) categ_class_func2
126 {
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];
131 }
132 - (int) categ_instance_func1
133 {
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." } */
141 }
142 - (int) categ_instance_func2
143 {
144 return [(id <Func>)super instance_func0];
145 }
146 @end
147
148 /* { dg-warning "messages without a matching method signature will be assumed to return .id. and accept .\.\.\.. as arguments" "" { target *-*-* } 0 } */