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