1 // RUN: %clang_cc1 -verify -Wno-deprecated-declarations -Wno-objc-root-class %s
11 - (id)retain; // expected-note{{instance method 'retain' is assumed to return an instance of its receiver type ('NSArray *')}}
19 // Do not infer when instance/class mismatches
25 // Do not infer when the return types mismatch.
26 - (Unrelated *)initAsUnrelated;
29 @interface NSString : NSObject
31 - (id)initWithCString:(const char*)string;
34 @interface NSArray : NSObject
41 @interface NSMutableArray : NSArray
45 + (Unrelated *)newUnrelated;
48 void test_inference(void) {
49 // Inference based on method family
50 __typeof__(([[NSString alloc] init])) *str = (NSString**)0;
51 __typeof__(([[[[NSString new] self] retain] autorelease])) *str2 = (NSString **)0;
52 __typeof__(([[NSString alloc] initWithCString:"blah"])) *str3 = (NSString**)0;
55 __typeof__(([[NSString new] copy])) *id1 = (id*)0;
57 // Not inferred due to instance/class mismatches
58 __typeof__(([[NSString new] newNotInferred])) *id2 = (id*)0;
59 __typeof__(([[NSString new] alloc])) *id3 = (id*)0;
60 __typeof__(([NSString self])) *id4 = (id*)0;
61 __typeof__(([NSString initWithBlarg])) *id5 = (id*)0;
63 // Not inferred due to return type mismatch
64 __typeof__(([[NSString alloc] initAsUnrelated])) *unrelated = (Unrelated**)0;
65 __typeof__(([NSBlah newUnrelated])) *unrelated2 = (Unrelated**)0;
68 NSArray *arr = [[NSMutableArray alloc] init];
69 NSMutableArray *marr = [arr retain]; // expected-warning{{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
72 @implementation NSBlah
73 + (Unrelated *)newUnrelated {
74 return (Unrelated *)0;
78 @implementation NSBlah (Cat)
79 + (Unrelated *)newUnrelated2 {
80 return (Unrelated *)0;
85 - (id)initBlah; // expected-note 2{{overridden method is part of the 'init' method family}}
89 - (Unrelated *)initBlah; // expected-warning{{method is expected to return an instance of its class type 'B', but is declared to return 'Unrelated *'}}
96 - (Unrelated *)initBlah { // expected-warning{{method is expected to return an instance of its class type 'C', but is declared to return 'Unrelated *'}}
97 return (Unrelated *)0;
102 + (id)newBlarg; // expected-note{{overridden method is part of the 'new' method family}}
106 + alloc; // expected-note{{overridden method is part of the 'alloc' method family}}
110 + (Unrelated *)newBlarg { // expected-warning{{method is expected to return an instance of its class type 'D', but is declared to return 'Unrelated *'}}
111 return (Unrelated *)0;
114 + (Unrelated *)alloc { // expected-warning{{method is expected to return an instance of its class type 'D', but is declared to return 'Unrelated *'}}
115 return (Unrelated *)0;
120 - (id)initBlah; // expected-note{{overridden method is part of the 'init' method family}}
125 - (int)initBlah; // expected-warning{{protocol method is expected to return an instance of the implementing class, but is declared to return 'int'}}
141 + (NSString *)newString;
148 + (NSString *)newString { return @"blah"; }
151 // <rdar://problem/9340699>
153 - (id)_ABC_init __attribute__((objc_method_family(init))); // expected-note {{method '_ABC_init' declared here}}
156 @interface G (Additions)
157 - (id)_ABC_init2 __attribute__((objc_method_family(init)));
160 @implementation G (Additions)
161 - (id)_ABC_init { // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
176 - (id<X>) initWithX // expected-note {{compiler has implicitly changed method 'initWithX' return type}}
178 return (id)self; // expected-warning {{casting 'Fail *' to incompatible type 'id<X>'}}
182 // <rdar://problem/11460990>
184 @interface WeirdNSString : NSString
185 - (id)initWithCString:(const char*)string, void *blah;
190 @protocol PMFilterManager
193 @interface UIViewController : NSObject
196 @implementation UIViewController
197 + (UIViewController<PMFilterManager> *)newFilterViewControllerForType // expected-note {{compiler has implicitly changed method 'newFilterViewControllerForType' return type}}
199 UIViewController<PMFilterManager> *filterVC;
200 return filterVC; // expected-warning {{incompatible pointer types casting 'UIViewController *' to type 'UIViewController<PMFilterManager> *'}}