1 // RUN: %clang_cc1 -fsyntax-only -Wno-incomplete-implementation -verify -fblocks %s
3 #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
4 #define NS_UNAVAILABLE __attribute__((unavailable))
6 void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{'objc_designated_initializer' attribute only applies to Objective-C methods}}
9 -(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
12 __attribute__((objc_root_class))
14 -(void)meth NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
15 -(id)init NS_DESIGNATED_INITIALIZER;
16 +(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
20 -(id)init2 NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
24 -(id)init3 NS_DESIGNATED_INITIALIZER;
29 -(id)init NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}}
30 +(id)init { return 0; }
31 -(id)init3 { return 0; }
32 -(id)init4 NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}} \
33 // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
36 __attribute__((objc_root_class))
38 -(id)initB1 NS_DESIGNATED_INITIALIZER; // expected-note 6 {{method marked as designated initializer of the class here}}
43 -(id)initB3 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
47 -(id)initB1 { return 0; }
48 -(id)initB2 { return 0; } // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
49 -(id)initB3 { return 0; }
53 -(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
54 -(id)initS2 NS_DESIGNATED_INITIALIZER;
55 -(id)initS3 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
60 -(id)initS4 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
64 -(id)initS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
68 return [super initB1];
70 -(id)initS3 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
71 return [super initB2]; // expected-warning {{designated initializer invoked a non-designated initializer}}
73 -(id)initS4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
74 return [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
89 -(id)initSS1 NS_DESIGNATED_INITIALIZER;
92 @implementation SS2 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
93 // expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
95 return [super initB1];
100 -(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
104 -(id)initSS1 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
107 @implementation SS3 // expected-warning {{method override for the designated initializer of the superclass '-initS1' not found}}
108 -(id)initSS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
109 return [super initB1]; // expected-warning {{designated initializer invoked a non-designated initializer}}
119 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
123 return [super initB3];
132 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
136 [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
140 void (^blk)(void) = ^{
141 [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
143 return [super initB3];
149 -(id)initS1 NS_DESIGNATED_INITIALIZER;
155 @implementation S6 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
156 // expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
158 return [super initB1];
160 -(id)initS2 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
161 return [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
164 return [self initB1];
167 return [self initS1];
170 [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
171 void (^blk)(void) = ^{
172 [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
174 return [self initS1];
176 -(id)initS6 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
187 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
208 __attribute__((objc_root_class))
214 -(id)initS8 NS_DESIGNATED_INITIALIZER;
229 @interface S9(secondInit)
238 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
243 @class GEOPDAnalyticMetadata; // expected-note {{forward declaration of class here}}
245 @implementation GEOPDAnalyticMetadata (PlaceCardExtras) // expected-error {{cannot find interface declaration for 'GEOPDAnalyticMetadata'}}
246 - (instancetype)initInProcess
252 __attribute__((objc_root_class))
254 - (instancetype)initWithStuff:(id)stuff __attribute__((objc_designated_initializer));
255 - (instancetype)init NS_UNAVAILABLE;
258 @implementation MyObject
265 __attribute__((objc_root_class))
267 -(id)initB4 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
271 @interface rdar16323233 : B4
272 -(id)initS4 NS_DESIGNATED_INITIALIZER;
275 @implementation rdar16323233
277 static id sSharedObject = (void*)0;
279 sSharedObject = [super initB4];
284 return [self initS4];
291 -(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
292 return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
300 -(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
301 return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
309 return [super initB4];
312 return [self initNew];
321 return [super initB4];
324 return [self initNew];
333 return [super initB4];
336 return [self initNew];
346 return [super initB4];
349 return [self initNew];
353 __attribute__((objc_root_class))
355 -(instancetype) init NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
358 @interface Test3 : NSObject
361 @implementation Test3
362 -(instancetype) initWithBasePath:(id)path {
365 -(instancetype) init {
366 return [self initWithBasePath:0];
370 @interface Test1 : NSObject
371 -(instancetype) init NS_DESIGNATED_INITIALIZER;
373 @implementation Test1
374 -(instancetype) init {
379 @interface SubTest1 : Test1
380 -(instancetype)init NS_UNAVAILABLE;
381 -(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
383 @implementation SubTest1
384 -(instancetype)initWithRequiredParameter:(id)foo {
389 @interface SubTest1Ext : Test1
390 -(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
392 // Mark 'init' as unavailable in the extension to silence warning.
393 @interface SubTest1Ext()
394 -(instancetype)init NS_UNAVAILABLE;
396 @implementation SubTest1Ext
397 -(instancetype)initWithRequiredParameter:(id)foo {
402 @interface Test2 : NSObject
404 @interface SubTest2 : Test2
406 @implementation SubTest2
407 -(instancetype) init { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
412 __attribute__((objc_root_class))
417 @interface Base : RootNoDI
423 @interface Derived : Base
424 - (instancetype)initWithInt:(int)n NS_DESIGNATED_INITIALIZER;
427 @implementation Derived
428 - (instancetype)initWithInt:(int)n
434 @interface ExtensionForMissingInterface() // expected-error{{cannot find interface declaration}}
435 - (instancetype)init NS_DESIGNATED_INITIALIZER;
438 @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}}
439 - (instancetype)init NS_DESIGNATED_INITIALIZER; // expected-error{{only applies to init methods of interface or class extension declarations}}
444 __attribute__((objc_designated_initializer))
445 __attribute__((objc_method_family(init)));
447 __attribute__((objc_method_family(init)))
448 __attribute__((objc_designated_initializer));
450 __attribute__((objc_designated_initializer, objc_method_family(init)));
452 __attribute__((objc_method_family(init), objc_designated_initializer));