call-super-2.m
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// RUN: %clang_cc1 -fsyntax-only -verify %s
#include <stddef.h>
typedef struct objc_object *id;
id objc_getClass(const char *s);
@interface Object
- (id) initWithInt: (int) i;
@end
@protocol Func
+ (int) class_func0;
- (int) instance_func0;
@end
@interface Derived: Object // expected-note {{receiver is instance of class declared here}}
+ (int) class_func1;
+ (int) class_func2;
+ (int) class_func3;
+ (int) class_func4;
+ (int) class_func5;
+ (int) class_func6;
+ (int) class_func7;
- (int) instance_func1;
- (int) instance_func2;
- (int) instance_func3;
- (int) instance_func4;
- (int) instance_func5;
- (int) instance_func6;
- (int) instance_func7;
- (id) initWithInt: (int) i;
@end
@implementation Derived
+ (int) class_func1
{
int i = (size_t)[self class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id'); did you mean '+class_func}}
return i + (size_t)[super class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}}
}
+ (int) class_func2
{
int i = [(id <Func>)self class_func0];
i += [(id <Func>)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
i += [(Class <Func>)self class_func0]; //
return i + [(Class <Func>)super class_func0]; // // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
+ (int) class_func3
{
return [(Object <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
+ (int) class_func4
{
return [(Derived <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
+ (int) class_func5
{
int i = (size_t)[Derived class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}}
return i + (size_t)[Object class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}}
}
+ (int) class_func6
{
return (size_t)[objc_getClass("Object") class_func1]; // GCC warns about this
}
+ (int) class_func7
{
return [objc_getClass("Derived") class_func1];
}
- (int) instance_func1
{
int i = (size_t)[self instance_func0]; // expected-warning {{instance method '-instance_func0' not found (return type defaults to 'id'); did you mean}}
return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0'}}
}
- (int) instance_func2
{
return [(id <Func>)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
- (int) instance_func3
{
return [(Object <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
- (int) instance_func4
{
return [(Derived <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
}
- (int) instance_func5
{
int i = (size_t)[Derived instance_func1]; // expected-warning {{class method '+instance_func1' not found (return type defaults to 'id')}}
return i + (size_t)[Object instance_func1]; // expected-warning {{class method '+instance_func1' not found (return type defaults to 'id')}}
}
- (int) instance_func6
{
return (size_t)[objc_getClass("Object") class_func1];
}
- (int) instance_func7
{
return [objc_getClass("Derived") class_func1];
}
- (id) initWithInt: (int) i
{
// Don't warn about parentheses here.
if (self = [super initWithInt: i]) {
[self instance_func1];
}
return self;
}
@end
@class C;
@interface A // expected-note {{receiver is instance of class declared here}}
- (instancetype)initWithCoder:(A *)coder;
@end
@interface B : A
@end
@implementation B
- (instancetype)initWithCoder:(C *)coder {
if (0 != (self = [super initWithCode:code])) // expected-error {{use of undeclared identifier 'code'}} expected-warning {{instance method '-initWithCode:' not found}}
return (void *)0;
return (void *)0;
}
@end