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