MissingDealloc.m revision 13dcd00615de5c4279d97bdf63cd5f0a14fd9dcc
1// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -warn-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %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// 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}}
44- (id)init {
45  if( (self = [super init]) ) {
46    a = @selector(a);
47    b = @selector(b);
48  }
49
50  return self;
51}
52@end
53
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
71//===------------------------------------------------------------------------===
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
91
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
119