1 // RUN: %clang_analyze_cc1 -analyzer-checker=osx.cocoa.Dealloc -fblocks -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=osx.cocoa.Dealloc -fblocks -verify -triple x86_64-apple-darwin10 -fobjc-arc %s
4 #define NON_ARC !__has_feature(objc_arc)
6 // No diagnostics expected under ARC.
8 // expected-no-diagnostics
11 typedef signed char BOOL;
13 - (BOOL)isEqual:(id)object;
17 @interface NSObject <NSObject> {}
22 typedef struct objc_selector *SEL;
24 //===------------------------------------------------------------------------===
25 // Do not warn about missing -dealloc method. Not enough context to know
26 // whether the ivar is retained or not.
28 @interface MissingDeallocWithIvar : NSObject {
33 @implementation MissingDeallocWithIvar
36 //===------------------------------------------------------------------------===
37 // Do not warn about missing -dealloc method. These properties are not
38 // retained or synthesized.
40 @interface MissingDeallocWithIntProperty : NSObject
41 @property (assign) int ivar;
44 @implementation MissingDeallocWithIntProperty
47 @interface MissingDeallocWithSELProperty : NSObject
48 @property (assign) SEL ivar;
51 @implementation MissingDeallocWithSELProperty
54 //===------------------------------------------------------------------------===
55 // Warn about missing -dealloc method.
57 @interface MissingDeallocWithCopyProperty : NSObject
58 @property (copy) NSObject *ivar;
62 // expected-warning@+2{{'MissingDeallocWithCopyProperty' lacks a 'dealloc' instance method but must release '_ivar'}}
64 @implementation MissingDeallocWithCopyProperty
67 @interface MissingDeallocWithRetainProperty : NSObject
68 @property (retain) NSObject *ivar;
72 // expected-warning@+2{{'MissingDeallocWithRetainProperty' lacks a 'dealloc' instance method but must release '_ivar'}}
74 @implementation MissingDeallocWithRetainProperty
77 @interface MissingDeallocWithMultipleProperties : NSObject
78 @property (retain) NSObject *ivar1;
79 @property (retain) NSObject *ivar2;
83 // expected-warning@+2{{'MissingDeallocWithMultipleProperties' lacks a 'dealloc' instance method but must release '_ivar1' and others}}
85 @implementation MissingDeallocWithMultipleProperties
88 @interface MissingDeallocWithIVarAndRetainProperty : NSObject {
91 @property (retain) NSObject *ivar1;
95 // expected-warning@+2{{'MissingDeallocWithIVarAndRetainProperty' lacks a 'dealloc' instance method but must release '_ivar1'}}
97 @implementation MissingDeallocWithIVarAndRetainProperty
100 @interface MissingDeallocWithReadOnlyRetainedProperty : NSObject
101 @property (readonly,retain) NSObject *ivar;
105 // expected-warning@+2{{'MissingDeallocWithReadOnlyRetainedProperty' lacks a 'dealloc' instance method but must release '_ivar'}}
107 @implementation MissingDeallocWithReadOnlyRetainedProperty
111 //===------------------------------------------------------------------------===
112 // Don't warn about iVars that are selectors.
114 @interface TestSELs : NSObject {
121 @implementation TestSELs
123 if( (self = [super init]) ) {
132 //===------------------------------------------------------------------------===
133 // Don't warn about iVars that are IBOutlets.
137 @interface HasOutlet : NSObject {
138 IBOutlet NSWindow *window;
142 @implementation HasOutlet // no-warning
145 //===------------------------------------------------------------------------===
146 // PR 3187: http://llvm.org/bugs/show_bug.cgi?id=3187
147 // - Disable the missing -dealloc check for classes that subclass SenTestCase
151 @interface SenTestCase : NSObject {}
154 @interface MyClassTest : SenTestCase {
155 NSString *resourcePath;
158 @property (retain) NSObject *ivar;
162 @interface NSBundle : NSObject {}
163 + (NSBundle *)bundleForClass:(Class)aClass;
164 - (NSString *)resourcePath;
167 @implementation MyClassTest
169 resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath];
172 // do something which uses resourcepath
176 //===------------------------------------------------------------------------===
177 // Don't warn for clases that aren't subclasses of NSObject
179 __attribute__((objc_root_class))
180 @interface NonNSObjectMissingDealloc
181 @property (retain) NSObject *ivar;
183 @implementation NonNSObjectMissingDealloc
187 //===------------------------------------------------------------------------===
188 // Don't crash on calls to dealloc as a class method.
190 @interface DeallocingClass : NSObject {}
192 @implementation DeallocingClass
194 [DeallocingClass dealloc]; // FIXME: Should we warn on this specifically?
197 // expected-warning@-2{{method possibly missing a [super dealloc] call}}