Daniel Dunbar | d427023 | 2009-01-20 23:17:32 +0000 | [diff] [blame] | 1 | // RUN: clang -analyze -warn-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s --verify |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 2 | typedef signed char BOOL; |
| 3 | @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| 4 | @interface NSObject <NSObject> {} |
| 5 | - (void)dealloc; |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 6 | - (id)init; |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 7 | @end |
| 8 | |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 9 | typedef struct objc_selector *SEL; |
| 10 | |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 11 | // <rdar://problem/6380411>: 'myproperty' has kind 'assign' and thus the |
| 12 | // assignment through the setter does not perform a release. |
| 13 | |
| 14 | @interface MyObject : NSObject { |
| 15 | id _myproperty; |
| 16 | } |
| 17 | @property(assign) id myproperty; |
| 18 | @end |
| 19 | |
| 20 | @implementation MyObject |
| 21 | @synthesize myproperty=_myproperty; // no-warning |
| 22 | - (void)dealloc { |
| 23 | self.myproperty = 0; |
| 24 | [super dealloc]; |
| 25 | } |
| 26 | @end |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 27 | |
| 28 | //===------------------------------------------------------------------------=== |
| 29 | // Don't warn about iVars that are selectors. |
| 30 | |
| 31 | @interface TestSELs : NSObject { |
| 32 | SEL a; |
| 33 | SEL b; |
| 34 | } |
| 35 | |
| 36 | @end |
| 37 | |
| 38 | @implementation TestSELs // no-warning |
| 39 | - (id)init { |
| 40 | if( (self = [super init]) ) { |
| 41 | a = @selector(a); |
| 42 | b = @selector(b); |
| 43 | } |
| 44 | |
| 45 | return self; |
| 46 | } |
| 47 | @end |
Ted Kremenek | 26b58cd | 2008-12-08 22:05:43 +0000 | [diff] [blame] | 48 | |
| 49 | //===------------------------------------------------------------------------=== |
| 50 | // Don't warn about iVars that are IBOutlets. |
| 51 | |
| 52 | #ifndef IBOutlet |
| 53 | #define IBOutlet |
| 54 | #endif |
| 55 | |
| 56 | @class NSWindow; |
| 57 | |
| 58 | @interface HasOutlet : NSObject { |
| 59 | IBOutlet NSWindow *window; |
| 60 | } |
| 61 | @end |
| 62 | |
| 63 | @implementation HasOutlet // no-warning |
| 64 | @end |
| 65 | |
Ted Kremenek | 183c6f2 | 2009-02-10 23:41:52 +0000 | [diff] [blame^] | 66 | //===------------------------------------------------------------------------=== |
| 67 | // <rdar://problem/6380411> |
| 68 | // Was bogus warning: "The '_myproperty' instance variable was not retained by a |
| 69 | // synthesized property but was released in 'dealloc'" |
| 70 | |
| 71 | @interface MyObject_rdar6380411 : NSObject { |
| 72 | id _myproperty; |
| 73 | } |
| 74 | @property(assign) id myproperty; |
| 75 | @end |
| 76 | |
| 77 | @implementation MyObject_rdar6380411 |
| 78 | @synthesize myproperty=_myproperty; |
| 79 | - (void)dealloc { |
| 80 | // Don't claim that myproperty is released since it the property |
| 81 | // has the 'assign' attribute. |
| 82 | self.myproperty = 0; // no-warning |
| 83 | [super dealloc]; |
| 84 | } |
| 85 | @end |