OSDN Git Service

* objc.dg/call-super-2.m: Make LP64-safe.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / call-super-2.m
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 } */
5
6 #include <objc/objc.h>
7 #include <objc/Object.h>
8
9 #ifdef __NEXT_RUNTIME__
10 #define OBJC_GETCLASS objc_getClass
11 #else
12 #define OBJC_GETCLASS objc_get_class
13 #endif
14
15 @protocol Func
16 + (int) class_func0;
17 - (int) instance_func0;
18 @end
19
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
36
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
43
44 @implementation Derived
45 + (int) class_func1
46 {
47    int i = (size_t)[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 + (size_t)[super class_func0];   /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
52 }
53 + (int) class_func2
54 {
55    int i = [(id <Func>)self class_func0];
56    return i + [(id <Func>)super class_func0];
57 }
58 + (int) class_func3
59 {
60    return [(Object <Func> *)super class_func0];
61 }
62 + (int) class_func4
63 {
64    return [(Derived <Func> *)super class_func0];
65 }   
66 + (int) class_func5
67 {
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." } */
70 }
71 + (int) class_func6
72 {
73    return (size_t)[OBJC_GETCLASS("Object") class_func1];  /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
74 }
75 + (int) class_func7
76 {
77    return [OBJC_GETCLASS("Derived") class_func1];
78 }
79 - (int) instance_func1
80 {
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." } */
83 }
84 - (int) instance_func2
85 {
86    return [(id <Func>)super instance_func0];
87 }
88 - (int) instance_func3
89 {
90    return [(Object <Func> *)super instance_func0];
91 }
92 - (int) instance_func4
93 {
94    return [(Derived <Func> *)super instance_func0];
95 }   
96 - (int) instance_func5
97 {
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." } */
100 }
101 - (int) instance_func6
102 {
103    return (size_t)[OBJC_GETCLASS("Object") class_func1]; /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
104 }
105 - (int) instance_func7
106 {
107    return [OBJC_GETCLASS("Derived") class_func1];
108 }
109 @end
110
111 @implementation Derived (Categ)
112 + (int) categ_class_func1
113 {
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." } */
119 }
120 + (int) categ_class_func2
121 {
122    int i = [(id <Func>)self class_func0];
123    return i + [(id <Func>)super class_func0];
124 }
125 - (int) categ_instance_func1
126 {
127    int i = (size_t)[self instance_func0];    /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
128    i += [(Derived <Func> *)self categ_instance_func2];
129    i += (size_t)[(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 += (size_t)[(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 + (size_t)[super instance_func0];   /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
134 }
135 - (int) categ_instance_func2
136 {
137    return [(id <Func>)super instance_func0];
138 }
139 @end