1 // RUN: %clang_cc1 -fsyntax-only -Wno-incomplete-implementation -verify -fblocks %s
3 #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
5 void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
8 -(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
11 __attribute__((objc_root_class))
13 -(void)meth NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
14 -(id)init NS_DESIGNATED_INITIALIZER;
15 +(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
19 -(id)init2 NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
23 -(id)init3 NS_DESIGNATED_INITIALIZER;
28 -(id)init NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}}
29 +(id)init { return 0; }
30 -(id)init3 { return 0; }
31 -(id)init4 NS_DESIGNATED_INITIALIZER { return 0; } // expected-error {{only applies to init methods of interface or class extension declarations}} \
32 // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
35 __attribute__((objc_root_class))
37 -(id)initB1 NS_DESIGNATED_INITIALIZER; // expected-note 6 {{method marked as designated initializer of the class here}}
42 -(id)initB3 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
46 -(id)initB1 { return 0; }
47 -(id)initB2 { return 0; } // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
48 -(id)initB3 { return 0; }
52 -(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
53 -(id)initS2 NS_DESIGNATED_INITIALIZER;
54 -(id)initS3 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
59 -(id)initS4 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
63 -(id)initS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
67 return [super initB1];
69 -(id)initS3 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
70 return [super initB2]; // expected-warning {{designated initializer invoked a non-designated initializer}}
72 -(id)initS4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
73 return [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
88 -(id)initSS1 NS_DESIGNATED_INITIALIZER;
91 @implementation SS2 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
92 // expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
94 return [super initB1];
99 -(id)initS1 NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
103 -(id)initSS1 NS_DESIGNATED_INITIALIZER; // expected-note 2 {{method marked as designated initializer of the class here}}
106 @implementation SS3 // expected-warning {{method override for the designated initializer of the superclass '-initS1' not found}}
107 -(id)initSS1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
108 return [super initB1]; // expected-warning {{designated initializer invoked a non-designated initializer}}
118 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
122 return [super initB3];
131 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
135 [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
139 void (^blk)(void) = ^{
140 [self initB1]; // expected-warning {{designated initializer should only invoke a designated initializer on 'super'}}
142 return [super initB3];
148 -(id)initS1 NS_DESIGNATED_INITIALIZER;
154 @implementation S6 // expected-warning {{method override for the designated initializer of the superclass '-initB1' not found}} \
155 // expected-warning {{method override for the designated initializer of the superclass '-initB3' not found}}
157 return [super initB1];
159 -(id)initS2 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
160 return [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
163 return [self initB1];
166 return [self initS1];
169 [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
170 void (^blk)(void) = ^{
171 [super initB1]; // expected-warning {{convenience initializer should not invoke an initializer on 'super'}}
173 return [self initS1];
175 -(id)initS6 { // expected-warning {{convenience initializer missing a 'self' call to another initializer}}
186 -(id)initB1 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
207 __attribute__((objc_root_class))
213 -(id)initS8 NS_DESIGNATED_INITIALIZER;
228 @interface S9(secondInit)
237 -(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
253 __attribute__((objc_root_class))
255 - (instancetype)initWithStuff:(id)stuff __attribute__((objc_designated_initializer));
256 - (instancetype)init __attribute__((unavailable));
259 @implementation MyObject
267 __attribute__((objc_root_class))
269 -(id)initB4 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
273 @interface rdar16323233 : B4
274 -(id)initS4 NS_DESIGNATED_INITIALIZER;
277 @implementation rdar16323233
279 static id sSharedObject = (void*)0;
281 sSharedObject = [super initB4];
286 return [self initS4];
293 -(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
294 return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
302 -(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
303 return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
311 return [super initB4];
314 return [self initNew];
323 return [super initB4];
326 return [self initNew];
335 return [super initB4];
338 return [self initNew];
348 return [super initB4];
351 return [self initNew];
355 __attribute__((objc_root_class))
357 -(instancetype) init NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
360 @interface Test3 : NSObject
363 @implementation Test3
364 -(instancetype) initWithBasePath:(id)path {
367 -(instancetype) init {
368 return [self initWithBasePath:0];
372 @interface Test1 : NSObject
373 -(instancetype) init NS_DESIGNATED_INITIALIZER;
375 @implementation Test1
376 -(instancetype) init {
382 @interface Test2 : NSObject
384 @interface SubTest2 : Test2
386 @implementation SubTest2
387 -(instancetype) init { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
392 __attribute__((objc_root_class))
397 @interface Base : RootNoDI
403 @interface Derived : Base
404 - (instancetype)initWithInt:(int)n NS_DESIGNATED_INITIALIZER;
407 @implementation Derived
408 - (instancetype)initWithInt:(int)n
414 @interface ExtensionForMissingInterface() // expected-error{{cannot find interface declaration}}
415 - (instancetype)init NS_DESIGNATED_INITIALIZER;
418 @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}}
419 - (instancetype)init NS_DESIGNATED_INITIALIZER; // expected-error{{only applies to init methods of interface or class extension declarations}}