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