blob: 502973a17341860a41440db1e9497ae6a4c07820 [file] [log] [blame]
Ted Kremenek8382cf52009-11-13 18:46:29 +00001// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -warn-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 Jahanian13dcd002009-11-21 19:53:08 +000042// FIXME!! This warning should not come out and is temporarily added so test 'passes'.
43@implementation TestSELs // expected-warning {{Objective-C class 'TestSELs' lacks a 'dealloc' instance method}}
Ted Kremenek63de7362008-12-08 22:01:50 +000044- (id)init {
45 if( (self = [super init]) ) {
46 a = @selector(a);
47 b = @selector(b);
48 }
49
50 return self;
51}
52@end
Ted Kremenek26b58cd2008-12-08 22:05:43 +000053
54//===------------------------------------------------------------------------===
55// Don't warn about iVars that are IBOutlets.
56
57#ifndef IBOutlet
58#define IBOutlet
59#endif
60
61@class NSWindow;
62
63@interface HasOutlet : NSObject {
64IBOutlet NSWindow *window;
65}
66@end
67
68@implementation HasOutlet // no-warning
69@end
70
Ted Kremenek183c6f22009-02-10 23:41:52 +000071//===------------------------------------------------------------------------===
72// <rdar://problem/6380411>
73// Was bogus warning: "The '_myproperty' instance variable was not retained by a
74// synthesized property but was released in 'dealloc'"
75
76@interface MyObject_rdar6380411 : NSObject {
77 id _myproperty;
78}
79@property(assign) id myproperty;
80@end
81
82@implementation MyObject_rdar6380411
83@synthesize myproperty=_myproperty;
84- (void)dealloc {
85 // Don't claim that myproperty is released since it the property
86 // has the 'assign' attribute.
87 self.myproperty = 0; // no-warning
88 [super dealloc];
89}
90@end
Ted Kremenekdd06e092009-02-13 22:26:30 +000091
92//===------------------------------------------------------------------------===
93// PR 3187: http://llvm.org/bugs/show_bug.cgi?id=3187
94// - Disable the missing -dealloc check for classes that subclass SenTestCase
95
96@class NSString;
97
98@interface SenTestCase : NSObject {}
99@end
100
101@interface MyClassTest : SenTestCase {
102 NSString *resourcePath;
103}
104@end
105
106@interface NSBundle : NSObject {}
107+ (NSBundle *)bundleForClass:(Class)aClass;
108- (NSString *)resourcePath;
109@end
110
111@implementation MyClassTest
112- (void)setUp {
113 resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath];
114}
115- (void)testXXX {
116 // do something which uses resourcepath
117}
118@end