1 // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=cocoa.SelfInit %s -verify
3 @class NSZone, NSCoder;
6 @protocol NSCopying - (id)copyWithZone:(NSZone *)zone;
8 @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone;
10 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
12 @interface NSObject <NSObject> {}
13 + (id)allocWithZone:(NSZone *)zone;
20 @interface NSProxy <NSObject> {}
23 //#import "Foundation/NSObject.h"
24 typedef unsigned NSUInteger;
25 typedef int NSInteger;
27 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
28 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
30 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
31 @end extern NSString * const NSBundleDidLoadNotification;
32 @interface NSAssertionHandler : NSObject {}
33 + (NSAssertionHandler *)currentHandler;
34 - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
36 extern NSString * const NSConnectionReplyMode;
38 @interface NSBundle : NSObject
39 +(id)loadNibNamed:(NSString*)s owner:(id)o;
46 static id _commonInit(MyObj *self) {
50 @interface MyObj : NSObject {
55 -(id)initWithSomething:(int)x;
59 @interface MyProxyObj : NSProxy {}
66 do { if (!((somePtr != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"init.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0);
67 return [self initWithSomething:0];
71 self = [self initWithSomething:0];
77 return [self initWithSomething:0];
88 - (id)initWithSomething:(int)x {
89 if ((self = [super init]))
100 [NSBundle loadNibNamed:@"Window" owner:self];
101 return [self initWithSomething:0];
105 [NSBundle loadNibNamed:@"Window" owner:myivar]; // no-warning
106 return [self initWithSomething:0];
110 if (0 != (self = [self _init]))
116 if ((self = [super init])) {
125 return self; // no-warning
129 myivar = 0; // no-warning
134 return self; // no-warning
139 return self; // expected-warning {{Returning 'self'}}
143 if (self == [super init]) {
144 myivar = 0; // expected-warning {{Instance variable used}}
146 return self; // expected-warning {{Returning 'self'}}
150 if (!(self = [super init]))
152 if (!(self = _commonInit(self)))
157 -(void)doSomething {}
161 @implementation MyProxyObj
163 - (id)init { return self; }