1 | // RUN: %clang_cc1 -fsyntax-only -Wunused-property-ivar -verify -Wno-objc-root-class %s |
2 | // rdar://14989999 |
3 | |
4 | @interface NSObject @end |
5 | |
6 | @interface Example : NSObject |
7 | @property (nonatomic, copy) id t; // expected-note {{property declared here}} |
8 | @property (nonatomic, copy) id u; // expected-note {{property declared here}} |
9 | @property (nonatomic, copy) id v; // expected-note {{property declared here}} |
10 | @property (nonatomic, copy) id w; |
11 | @property (nonatomic, copy) id x; // expected-note {{property declared here}} |
12 | @property (nonatomic, copy) id y; // expected-note {{property declared here}} |
13 | @property (nonatomic, copy) id z; |
14 | @property (nonatomic, copy) id ok; |
15 | @end |
16 | |
17 | @implementation Example |
18 | - (void) setX:(id)newX { // expected-warning {{ivar '_x' which backs the property is not referenced in this property's accessor}} |
19 | _y = newX; |
20 | } |
21 | - (id) y { // expected-warning {{ivar '_y' which backs the property is not referenced in this property's accessor}} |
22 | return _v; |
23 | } |
24 | |
25 | - (void) setV:(id)newV { // expected-warning {{ivar '_v' which backs the property is not referenced in this property's accessor}} |
26 | _y = newV; |
27 | } |
28 | |
29 | // No warning here because there is no backing ivar. |
30 | // both setter/getter are user defined. |
31 | - (void) setW:(id)newW { |
32 | _y = newW; |
33 | } |
34 | - (id) w { |
35 | return _v; |
36 | } |
37 | |
38 | - (id) u { // expected-warning {{ivar '_u' which backs the property is not referenced in this property's accessor}} |
39 | return _v; |
40 | } |
41 | |
42 | @synthesize ok = okIvar; |
43 | - (void) setOk:(id)newOk { |
44 | okIvar = newOk; |
45 | } |
46 | |
47 | @synthesize t = tIvar; |
48 | - (void) setT:(id)newT { // expected-warning {{ivar 'tIvar' which backs the property is not referenced in this property's accessor}} |
49 | okIvar = newT; |
50 | } |
51 | @end |
52 | |
53 | // rdar://15473432 |
54 | typedef char BOOL; |
55 | @interface CalDAVServerVersion { |
56 | BOOL _supportsTimeRangeFilterWithoutEndDate; |
57 | } |
58 | @property (nonatomic, readonly,nonatomic) BOOL supportsTimeRangeFilterWithoutEndDate; |
59 | @end |
60 | |
61 | @interface CalDAVConcreteServerVersion : CalDAVServerVersion { |
62 | } |
63 | @end |
64 | |
65 | @interface CalendarServerVersion : CalDAVConcreteServerVersion |
66 | @end |
67 | |
68 | @implementation CalDAVServerVersion |
69 | @synthesize supportsTimeRangeFilterWithoutEndDate=_supportsTimeRangeFilterWithoutEndDate; |
70 | @end |
71 | |
72 | @implementation CalendarServerVersion |
73 | -(BOOL)supportsTimeRangeFilterWithoutEndDate { |
74 | return 0; |
75 | } |
76 | @end |
77 | |
78 | // rdar://15630719 |
79 | @interface CDBModifyRecordsOperation : NSObject |
80 | @property (nonatomic, assign) BOOL atomic; |
81 | @end |
82 | |
83 | @class NSString; |
84 | |
85 | @implementation CDBModifyRecordsOperation |
86 | - (void)setAtomic:(BOOL)atomic { |
87 | if (atomic == __objc_yes) { |
88 | NSString *recordZoneID = 0; |
89 | } |
90 | _atomic = atomic; |
91 | } |
92 | @end |
93 | |
94 | // rdar://15728901 |
95 | @interface GATTOperation : NSObject { |
96 | long operation; |
97 | } |
98 | @property(assign) long operation; |
99 | @end |
100 | |
101 | @implementation GATTOperation |
102 | @synthesize operation; |
103 | + (id) operation { |
104 | return 0; |
105 | } |
106 | @end |
107 | |
108 | // rdar://15727327 |
109 | @interface Radar15727327 : NSObject |
110 | @property (assign, readonly) long p; |
111 | @property (assign) long q; // expected-note 2 {{property declared here}} |
112 | @property (assign, readonly) long r; // expected-note {{property declared here}} |
113 | - (long)Meth; |
114 | @end |
115 | |
116 | @implementation Radar15727327 |
117 | @synthesize p; |
118 | @synthesize q; |
119 | @synthesize r; |
120 | - (long)Meth { return p; } |
121 | - (long) p { [self Meth]; return 0; } |
122 | - (long) q { return 0; } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}} |
123 | - (void) setQ : (long) val { } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}} |
124 | - (long) r { [self Meth]; return p; } // expected-warning {{ivar 'r' which backs the property is not referenced in this property's accessor}} |
125 | @end |
126 | |
127 | @interface I1 |
128 | @property (readonly) int p1; |
129 | @property (readonly) int p2; // expected-note {{property declared here}} |
130 | @end |
131 | |
132 | @implementation I1 |
133 | @synthesize p1=_p1; |
134 | @synthesize p2=_p2; |
135 | |
136 | -(int)p1 { |
137 | return [self getP1]; |
138 | } |
139 | -(int)getP1 { |
140 | return _p1; |
141 | } |
142 | -(int)getP2 { |
143 | return _p2; |
144 | } |
145 | -(int)p2 { // expected-warning {{ivar '_p2' which backs the property is not referenced in this property's accessor}} |
146 | Radar15727327 *o; |
147 | return [o Meth]; |
148 | } |
149 | @end |
150 | |
151 | // rdar://15873425 |
152 | @protocol MyProtocol |
153 | @property (nonatomic, readonly) int myProperty; |
154 | @end |
155 | |
156 | @interface MyFirstClass : NSObject <MyProtocol> |
157 | @end |
158 | |
159 | @interface MySecondClass : NSObject <MyProtocol> |
160 | @end |
161 | |
162 | @implementation MyFirstClass |
163 | @synthesize myProperty; |
164 | @end |
165 | |
166 | @implementation MySecondClass |
167 | @dynamic myProperty; |
168 | -(int)myProperty // should not warn; property is dynamic |
169 | { |
170 | return 0; |
171 | } |
172 | @end |
173 | |
174 | // rdar://15890251 |
175 | @class NSURL; |
176 | |
177 | @protocol MCCIDURLProtocolDataProvider |
178 | @required |
179 | @property(strong, atomic, readonly) NSURL *cidURL; |
180 | @property(strong, atomic, readonly) NSURL *cidURL1; // expected-note {{property declared here}} |
181 | @end |
182 | |
183 | @interface UnrelatedClass : NSObject <MCCIDURLProtocolDataProvider> |
184 | @end |
185 | |
186 | @implementation UnrelatedClass |
187 | @synthesize cidURL = _cidURL; |
188 | @synthesize cidURL1 = _cidURL1; |
189 | @end |
190 | |
191 | @interface MUIWebAttachmentController : NSObject <MCCIDURLProtocolDataProvider> |
192 | @end |
193 | |
194 | |
195 | @implementation MUIWebAttachmentController |
196 | - (NSURL *)cidURL { |
197 | return 0; |
198 | } |
199 | @synthesize cidURL1 = _cidURL1; |
200 | - (NSURL *)cidURL1 { // expected-warning {{ivar '_cidURL1' which backs the property is not referenced in this property's accessor}} |
201 | return 0; |
202 | } |
203 | @end |
204 | |