MissingDealloc.m revision 3065cf9ecc883715edbd3bf875acb2cab531138e
1// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.osx.cocoa.Dealloc %s -verify 2typedef signed char BOOL; 3@protocol NSObject 4- (BOOL)isEqual:(id)object; 5- (Class)class; 6@end 7 8@interface NSObject <NSObject> {} 9- (void)dealloc; 10- (id)init; 11@end 12 13typedef struct objc_selector *SEL; 14 15// <rdar://problem/6380411>: 'myproperty' has kind 'assign' and thus the 16// assignment through the setter does not perform a release. 17 18@interface MyObject : NSObject { 19 id _myproperty; 20} 21@property(assign) id myproperty; 22@end 23 24@implementation MyObject 25@synthesize myproperty=_myproperty; // no-warning 26- (void)dealloc { 27 self.myproperty = 0; 28 [super dealloc]; 29} 30@end 31 32//===------------------------------------------------------------------------=== 33// Don't warn about iVars that are selectors. 34 35@interface TestSELs : NSObject { 36 SEL a; 37 SEL b; 38} 39 40@end 41 42@implementation TestSELs 43- (id)init { 44 if( (self = [super init]) ) { 45 a = @selector(a); 46 b = @selector(b); 47 } 48 49 return self; 50} 51@end 52 53//===------------------------------------------------------------------------=== 54// Don't warn about iVars that are IBOutlets. 55 56@class NSWindow; 57 58@interface HasOutlet : NSObject { 59IBOutlet NSWindow *window; 60} 61@end 62 63@implementation HasOutlet // no-warning 64@end 65 66//===------------------------------------------------------------------------=== 67// <rdar://problem/6380411> 68// Was bogus warning: "The '_myproperty' instance variable was not retained by a 69// synthesized property but was released in 'dealloc'" 70 71@interface MyObject_rdar6380411 : NSObject { 72 id _myproperty; 73} 74@property(assign) id myproperty; 75@end 76 77@implementation MyObject_rdar6380411 78@synthesize myproperty=_myproperty; 79- (void)dealloc { 80 // Don't claim that myproperty is released since it the property 81 // has the 'assign' attribute. 82 self.myproperty = 0; // no-warning 83 [super dealloc]; 84} 85@end 86 87//===------------------------------------------------------------------------=== 88// PR 3187: http://llvm.org/bugs/show_bug.cgi?id=3187 89// - Disable the missing -dealloc check for classes that subclass SenTestCase 90 91@class NSString; 92 93@interface SenTestCase : NSObject {} 94@end 95 96@interface MyClassTest : SenTestCase { 97 NSString *resourcePath; 98} 99@end 100 101@interface NSBundle : NSObject {} 102+ (NSBundle *)bundleForClass:(Class)aClass; 103- (NSString *)resourcePath; 104@end 105 106@implementation MyClassTest 107- (void)setUp { 108 resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath]; 109} 110- (void)testXXX { 111 // do something which uses resourcepath 112} 113@end 114