1 // RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=osx.cocoa.UnusedIvars -verify -Wno-objc-root-class %s
3 //===--- BEGIN: Delta-debugging reduced headers. --------------------------===//
7 - (oneway void)release;
9 @interface NSObject <NSObject> {}
14 //===--- END: Delta-debugging reduced headers. ----------------------------===//
16 // This test case tests the basic functionality of the unused ivar test.
19 int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}}
22 @implementation TestA @end
24 // This test case tests whether the unused ivar check handles blocks that
25 // reference an instance variable.
26 @interface TestB : NSObject {
28 id _ivar; // no-warning
30 @property (readwrite,retain) id ivar;
35 __attribute__((__blocks__(byref))) id value = ((void*)0);
36 void (^b)(void) = ^{ value = _ivar; };
41 - (void)setIvar:(id)newValue {
42 void (^b)(void) = ^{ [_ivar release]; _ivar = [newValue retain]; };
47 // Confirm that the checker respects [[clang::suppress]].
50 [[clang::suppress]] int x; // no-warning
53 @implementation TestC @end
56 //===----------------------------------------------------------------------===//
57 // Detect that ivar is in use, if used in category in the same file as the
59 //===----------------------------------------------------------------------===//
60 @protocol Protocol6260004
64 @interface RDar6260004 {
69 @implementation RDar6260004 @end
70 @implementation RDar6260004 (Protocol6260004)
76 //===----------------------------------------------------------------------===//
77 // ivars referenced by lexically nested functions should not be flagged as
79 //===----------------------------------------------------------------------===//
80 @interface RDar7254495 {
86 @implementation RDar7254495
87 int radar_7254495(RDar7254495 *a) {
92 //===----------------------------------------------------------------------===//
93 // Consult attribute((unused)) to silence warnings about unused instance
95 //===----------------------------------------------------------------------===//
96 @interface RDar7353683 {
98 id x __attribute__((unused));
102 @implementation RDar7353683
105 //===----------------------------------------------------------------------===//
106 // Unused bitfield ivars trigger cause weird diagnostic:
107 // "Instance variable '' in class..."
108 //===----------------------------------------------------------------------===//
109 @interface RDar8481311 {
111 unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}}
115 @implementation RDar8481311
119 @interface Radar11059352_1 {
121 NSString *_pathString;
123 @property (readonly, strong) NSString *pathString;
126 @interface Radar11059352 {
128 Radar11059352_1 *_workspacePath;
132 @implementation Radar11059352
134 - (void)useWorkspace {
135 NSString *workspacePathString = _workspacePath.pathString;