attr-designated-init.m
11.8 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
// RUN: %clang_cc1 -fsyntax-only -Wno-incomplete-implementation -verify -fblocks %s
#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
#define NS_UNAVAILABLE __attribute__((unavailable))
void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{'objc_designated_initializer' attribute only applies to Objective-C methods}}
@protocol P1
-(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
@end
__attribute__((objc_root_class))
@interface I1
-(void)meth NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
-(id)init NS_DESIGNATED_INITIALIZER;
+(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
@end
@interface I1(cat)
-(id)init2 NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
@end
@interface I1()
-(id)init3 NS_DESIGNATED_INITIALIZER;
@end
@implementation I1
-(void)meth {}
-(id)init NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}}
+(id)init { return 0; }
-(id)init3 { return 0; }
-(id)init4 NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}} \
// expected-warning {{convenience initializer missing a 'self' call to another initializer}}
@end
__attribute__((objc_root_class))
@interface B1
-(id)initB1 NS_DESIGNATED_INITIALIZER; // expected-note 6 {{method marked as designated initializer of the class here}}
-(id)initB2;
@end
@interface B1()
-(id)initB3 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
@end;
@implementation B1
-(id)initB1 { return 0; }
-(id)initB2 { return 0; } // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
-(id)initB3 { return 0; }
@end
@interface S1 : B1
-(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
-(id)initS2 NS_DESIGNATED_INITIALIZER;
-(id)initS3 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
-(id)initB1;
@end
@interface S1()
-(id)initS4 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
@end
@implementation S1
-(id)initS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return 0;
}
-(id)initS2 {
return [super initB1];
}
-(id)initS3 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return [super initB2]; // expected-warning {{designated initializer invoked a non-designated initializer}}
}
-(id)initS4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
}
-(id)initB1 {
return [self initS1];
}
-(id)initB3 {
return [self initS1];
}
@end
@interface S2 : B1
-(id)initB1;
@end
@interface SS2 : S2
-(id)initSS1 NS_DESIGNATED_INITIALIZER;
@end
@implementation SS2 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
// expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
-(id)initSS1 {
return [super initB1];
}
@end
@interface S3 : B1
-(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
@end
@interface SS3 : S3
-(id)initSS1 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
@end
@implementation SS3 // expected-warning {{method override for the designated initializer of the superclass '-initS1' not found}}
-(id)initSS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return [super initB1]; // expected-warning {{designated initializer invoked a non-designated initializer}}
}
@end
@interface S4 : B1
-(id)initB1;
-(id)initB3;
@end
@implementation S4
-(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return 0;
}
-(id)initB3 {
return [super initB3];
}
@end
@interface S5 : B1
-(void)meth;
@end
@implementation S5
-(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return 0;
}
-(id)initB3 {
[self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
S5 *s;
[s initB1];
[self meth];
void (^blk)(void) = ^{
[self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
};
return [super initB3];
}
-(void)meth {}
@end
@interface S6 : B1
-(id)initS1 NS_DESIGNATED_INITIALIZER;
-(id)initS2;
-(id)initS3;
-(id)initS4;
@end
@implementation S6 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
// expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
-(id)initS1 {
return [super initB1];
}
-(id)initS2 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
return [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
}
-(id)initS3 {
return [self initB1];
}
-(id)initS4 {
return [self initS1];
}
-(id)initS5 {
[super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
void (^blk)(void) = ^{
[super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
};
return [self initS1];
}
-(id)initS6 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
S6 *s;
return [s initS1];
}
@end
@interface SS4 : S4
-(id)initB1;
@end
@implementation SS4
-(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return 0;
}
@end
@interface S7 : B1
-(id)initB1;
-(id)initB3;
-(id)initNewOne;
@end
@interface SS7 : S7
-(id)initB1;
@end
@implementation SS7
-(id)initB1 {
return 0;
}
@end
__attribute__((objc_root_class))
@interface B2
-(id)init;
@end
@interface S8: B2
-(id)initS8 NS_DESIGNATED_INITIALIZER;
@end
@implementation S8
-(id)initS8
{
return [super init];
}
@end
@interface S9 : B1
-(id)initB1;
-(id)initB3;
@end
@interface S9(secondInit)
-(id)initNewOne;
@end
@interface SS9 : S9
-(id)initB1;
@end
@implementation SS9
-(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return 0;
}
@end
// rdar://16261494
@class GEOPDAnalyticMetadata; // expected-note {{forward declaration of class here}}
@implementation GEOPDAnalyticMetadata (PlaceCardExtras) // expected-error {{cannot find interface declaration for 'GEOPDAnalyticMetadata'}}
- (instancetype)initInProcess
{
return ((void*)0);
}
@end
// rdar://16305460
__attribute__((objc_root_class))
@interface MyObject
- (instancetype)initWithStuff:(id)stuff __attribute__((objc_designated_initializer));
- (instancetype)init NS_UNAVAILABLE;
@end
@implementation MyObject
- (instancetype)init
{
return ((void*)0);
}
@end
// rdar://16323233
__attribute__((objc_root_class))
@interface B4
-(id)initB4 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
-(id)initNonDI;
@end
@interface rdar16323233 : B4
-(id)initS4 NS_DESIGNATED_INITIALIZER;
@end
@implementation rdar16323233
-(id)initS4 {
static id sSharedObject = (void*)0;
(void)^(void) {
sSharedObject = [super initB4];
};
return 0;
}
-(id)initB4 {
return [self initS4];
}
@end
@interface S1B4 : B4
@end
@implementation S1B4
-(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
}
@end
@interface S2B4 : B4
-(id)initB4;
@end
@implementation S2B4
-(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
}
@end
@interface S3B4 : B4
@end
@implementation S3B4
-(id)initNew {
return [super initB4];
}
-(id)initB4 {
return [self initNew];
}
@end
@interface S4B4 : B4
-(id)initNew;
@end
@implementation S4B4
-(id)initNew {
return [super initB4];
}
-(id)initB4 {
return [self initNew];
}
@end
@interface S5B4 : B4
-(id)initB4;
@end
@implementation S5B4
-(id)initNew {
return [super initB4];
}
-(id)initB4 {
return [self initNew];
}
@end
@interface S6B4 : B4
-(id)initNew;
-(id)initB4;
@end
@implementation S6B4
-(id)initNew {
return [super initB4];
}
-(id)initB4 {
return [self initNew];
}
@end
__attribute__((objc_root_class))
@interface NSObject
-(instancetype) init NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
@end
@interface Test3 : NSObject
@end
@implementation Test3
-(instancetype) initWithBasePath:(id)path {
return [super init];
}
-(instancetype) init {
return [self initWithBasePath:0];
}
@end
@interface Test1 : NSObject
-(instancetype) init NS_DESIGNATED_INITIALIZER;
@end
@implementation Test1
-(instancetype) init {
return self;
}
@end
@interface SubTest1 : Test1
-(instancetype)init NS_UNAVAILABLE;
-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
@end
@implementation SubTest1
-(instancetype)initWithRequiredParameter:(id)foo {
return [super init];
}
@end
@interface SubTest1Ext : Test1
-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
@end
// Mark 'init' as unavailable in the extension to silence warning.
@interface SubTest1Ext()
-(instancetype)init NS_UNAVAILABLE;
@end
@implementation SubTest1Ext
-(instancetype)initWithRequiredParameter:(id)foo {
return [super init];
}
@end
@interface Test2 : NSObject
@end
@interface SubTest2 : Test2
@end
@implementation SubTest2
-(instancetype) init { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
return self;
}
@end
__attribute__((objc_root_class))
@interface RootNoDI
-(id)init;
@end
@interface Base : RootNoDI
@end
@implementation Base
@end
@interface Derived : Base
- (instancetype)initWithInt:(int)n NS_DESIGNATED_INITIALIZER;
@end
@implementation Derived
- (instancetype)initWithInt:(int)n
{
return [super init];
}
@end
@interface ExtensionForMissingInterface() // expected-error{{cannot find interface declaration}}
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}}
- (instancetype)init NS_DESIGNATED_INITIALIZER; // expected-error{{only applies to init methods of interface or class extension declarations}}
@end
@interface TwoAttrs
-(instancetype)foo
__attribute__((objc_designated_initializer))
__attribute__((objc_method_family(init)));
-(instancetype)bar
__attribute__((objc_method_family(init)))
__attribute__((objc_designated_initializer));
-(instancetype)baz
__attribute__((objc_designated_initializer, objc_method_family(init)));
-(instancetype)quux
__attribute__((objc_method_family(init), objc_designated_initializer));
@end