2010-11-11 Jakub Jelinek <jakub@redhat.com>
[official-gcc.git] / gcc / testsuite / objc.dg / call-super-2.m
blob190c407f79611c393d3e81466c06f573c8b72d25
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/Object1.h"
6 #include "../objc-obj-c++-shared/next-mapping.h"
7 #include <stddef.h>
9 @protocol Func
10 + (int) class_func0;
11 - (int) instance_func0;
12 @end
14 @interface Derived: Object
15 + (int) class_func1;
16 + (int) class_func2;
17 + (int) class_func3;
18 + (int) class_func4;
19 + (int) class_func5;
20 + (int) class_func6;
21 + (int) class_func7;
22 - (int) instance_func1;
23 - (int) instance_func2;
24 - (int) instance_func3;
25 - (int) instance_func4;
26 - (int) instance_func5;
27 - (int) instance_func6;
28 - (int) instance_func7;
29 @end
31 @interface Derived (Categ)
32 + (int) categ_class_func1;
33 + (int) categ_class_func2;
34 - (int) categ_instance_func1;
35 - (int) categ_instance_func2;
36 @end
38 @implementation Derived
39 + (int) class_func1
41    int i = (size_t)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
42    return i + (size_t)[super class_func0];   /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
44 + (int) class_func2
46    int i = [(id <Func>)self class_func0];  /* { dg-warning ".\\-class_func0. not found in protocol" } */
47    i += [(id <Func>)super class_func0];    /* { dg-warning ".\\-class_func0. not found in protocol" } */
48    i += [(Class <Func>)self class_func0];
49    return i + [(Class <Func>)super class_func0];
51 + (int) class_func3
53    return [(Object <Func> *)super class_func0];
55 + (int) class_func4
57    return [(Derived <Func> *)super class_func0];
58 }   
59 + (int) class_func5
61    int i = (size_t)[Derived class_func0];    /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
62    return i + (size_t)[Object class_func0];  /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
64 + (int) class_func6
66    return (size_t)[objc_get_class("Object") class_func1];  /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
68 + (int) class_func7
70    return [objc_get_class("Derived") class_func1];
72 - (int) instance_func1
74    int i = (size_t)[self instance_func0];     /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
75    return i + (size_t)[super instance_func0]; /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
77 - (int) instance_func2
79    return [(id <Func>)super instance_func0];
81 - (int) instance_func3
83    return [(Object <Func> *)super instance_func0];
85 - (int) instance_func4
87    return [(Derived <Func> *)super instance_func0];
88 }   
89 - (int) instance_func5
91    int i = (size_t)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
92    return i + (size_t)[Object instance_func1]; /* { dg-warning ".Object. may not respond to .\\+instance_func1." } */
94 - (int) instance_func6
96    return (size_t)[objc_get_class("Object") class_func1]; /* { dg-warning ".Object. may not respond to .\\+class_func1." } */
98 - (int) instance_func7
100    return [objc_get_class("Derived") class_func1];
102 @end
104 @implementation Derived (Categ)
105 + (int) categ_class_func1
107    int i = (size_t)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
108    i += [self class_func1];
109    i += [self categ_class_func2];
110    i += (size_t)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
111    return i + (size_t)[super class_func0];   /* { dg-warning ".Object. may not respond to .\\+class_func0." } */
113 + (int) categ_class_func2
115    int i = [(id <Func>)self class_func0];  /* { dg-warning ".\\-class_func0. not found in protocol" } */
116    i += [(id <Func>)super class_func0];    /* { dg-warning ".\\-class_func0. not found in protocol" } */
117    i += [(Class <Func>)self class_func0];
118    return i + [(Class <Func>)super class_func0];
120 - (int) categ_instance_func1
122    int i = (size_t)[self instance_func0];    /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
123    i += [(Derived <Func> *)self categ_instance_func2];
124    i += (size_t)[(Object <Func> *)self categ_instance_func2]; /* { dg-warning ".Object. may not respond to .\\-categ_instance_func2." } */
125    /* { dg-warning ".\\-categ_instance_func2. not found in protocol" "" { target *-*-* } 124 } */
126    i += (size_t)[(id <Func>)self categ_instance_func2];  /* { dg-warning ".\\-categ_instance_func2. not found in protocol" } */
127    i += [(id)self categ_instance_func2];
128    return i + (size_t)[super instance_func0];   /* { dg-warning ".Object. may not respond to .\\-instance_func0." } */
130 - (int) categ_instance_func2
132    return [(id <Func>)super instance_func0];
134 @end
136 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
137 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
138 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */