blob: bfd968a9a1a6f747f5f6b1d09464d1510c3062e3 [file] [log] [blame]
Ted Kremenek7909fc82010-02-05 01:59:21 +00001// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify
Ted Kremeneke0bb8042008-12-08 21:59:21 +00002typedef signed char BOOL;
Ted Kremenekdd06e092009-02-13 22:26:30 +00003@protocol NSObject
4- (BOOL)isEqual:(id)object;
5- (Class)class;
6@end
7
Ted Kremeneke0bb8042008-12-08 21:59:21 +00008@interface NSObject <NSObject> {}
9- (void)dealloc;
Ted Kremenek63de7362008-12-08 22:01:50 +000010- (id)init;
Ted Kremeneke0bb8042008-12-08 21:59:21 +000011@end
12
Ted Kremenek63de7362008-12-08 22:01:50 +000013typedef struct objc_selector *SEL;
14
Ted Kremeneke0bb8042008-12-08 21:59:21 +000015// <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
Ted Kremenek63de7362008-12-08 22:01:50 +000031
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
Fariborz Jahanian04765ac2009-11-23 18:04:25 +000042@implementation TestSELs
Ted Kremenek63de7362008-12-08 22:01:50 +000043- (id)init {
44 if( (self = [super init]) ) {
45 a = @selector(a);
46 b = @selector(b);
47 }
48
49 return self;
50}
51@end
Ted Kremenek26b58cd2008-12-08 22:05:43 +000052
53//===------------------------------------------------------------------------===
54// Don't warn about iVars that are IBOutlets.
55
56#ifndef IBOutlet
57#define IBOutlet
58#endif
59
60@class NSWindow;
61
62@interface HasOutlet : NSObject {
63IBOutlet NSWindow *window;
64}
65@end
66
67@implementation HasOutlet // no-warning
68@end
69
Ted Kremenek183c6f22009-02-10 23:41:52 +000070//===------------------------------------------------------------------------===
71// <rdar://problem/6380411>
72// Was bogus warning: "The '_myproperty' instance variable was not retained by a
73// synthesized property but was released in 'dealloc'"
74
75@interface MyObject_rdar6380411 : NSObject {
76 id _myproperty;
77}
78@property(assign) id myproperty;
79@end
80
81@implementation MyObject_rdar6380411
82@synthesize myproperty=_myproperty;
83- (void)dealloc {
84 // Don't claim that myproperty is released since it the property
85 // has the 'assign' attribute.
86 self.myproperty = 0; // no-warning
87 [super dealloc];
88}
89@end
Ted Kremenekdd06e092009-02-13 22:26:30 +000090
91//===------------------------------------------------------------------------===
92// PR 3187: http://llvm.org/bugs/show_bug.cgi?id=3187
93// - Disable the missing -dealloc check for classes that subclass SenTestCase
94
95@class NSString;
96
97@interface SenTestCase : NSObject {}
98@end
99
100@interface MyClassTest : SenTestCase {
101 NSString *resourcePath;
102}
103@end
104
105@interface NSBundle : NSObject {}
106+ (NSBundle *)bundleForClass:(Class)aClass;
107- (NSString *)resourcePath;
108@end
109
110@implementation MyClassTest
111- (void)setUp {
112 resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath];
113}
114- (void)testXXX {
115 // do something which uses resourcepath
116}
117@end