Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple x86_64-apple-darwin10 -analyze -warn-objc-unused-ivars %s -verify |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 2 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 3 | //===--- BEGIN: Delta-debugging reduced headers. --------------------------===// |
| 4 | |
| 5 | @protocol NSObject |
| 6 | - (id)retain; |
| 7 | - (oneway void)release; |
| 8 | @end |
| 9 | @interface NSObject <NSObject> {} |
| 10 | - (id)init; |
| 11 | + (id)alloc; |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 12 | @end |
| 13 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 14 | //===--- END: Delta-debugging reduced headers. ----------------------------===// |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 15 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 16 | // This test case tests the basic functionality of the unused ivar test. |
| 17 | @interface TestA { |
| 18 | @private |
| 19 | int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}} |
| 20 | } |
| 21 | @end |
| 22 | @implementation TestA @end |
| 23 | |
| 24 | // This test case tests whether the unused ivar check handles blocks that |
| 25 | // reference an instance variable. (<rdar://problem/7075531>) |
| 26 | @interface TestB : NSObject { |
| 27 | @private |
| 28 | id _ivar; // no-warning |
| 29 | } |
| 30 | @property (readwrite,retain) id ivar; |
| 31 | @end |
| 32 | |
| 33 | @implementation TestB |
| 34 | - (id)ivar { |
| 35 | __attribute__((__blocks__(byref))) id value = ((void*)0); |
| 36 | void (^b)() = ^{ value = _ivar; }; |
| 37 | b(); |
| 38 | return value; |
| 39 | } |
| 40 | |
| 41 | - (void)setIvar:(id)newValue { |
| 42 | void (^b)() = ^{ [_ivar release]; _ivar = [newValue retain]; }; |
| 43 | b(); |
| 44 | } |
| 45 | @end |