32 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-output=text -verify %s2 3@protocol NSObject4@end5 6@interface NSObject <NSObject> {}7- (id)init;8+ (id)alloc;9- (id)autorelease;10@end11 12@interface Foo : NSObject13@property(nonatomic) int bar;14@end15 16@implementation Foo17-(int)bar {18 return 0;19}20@end21 22int baz() {23 Foo *f = [Foo alloc];24 // expected-note@-1 {{'f' initialized here}}25 // expected-note@-2 {{Method returns an instance of Foo with a +1 retain count}}26 27 return f.bar;28 // expected-warning@-1 {{Potential leak of an object stored into 'self' [osx.cocoa.RetainCount]}}29 // expected-note@-2 {{Passing value via implicit parameter 'self'}}30 // expected-note@-3 {{Object leaked: object allocated and stored into 'self' is not referenced later in this execution path and has a retain count of +1}}31}32