197 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -Wunused-property-ivar -verify -Wno-objc-root-class %s2 3@interface NSObject @end4 5@interface Example : NSObject6@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@end15 16@implementation Example17- (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@end51 52typedef char BOOL;53@interface CalDAVServerVersion {54 BOOL _supportsTimeRangeFilterWithoutEndDate;55}56@property (nonatomic, readonly,nonatomic) BOOL supportsTimeRangeFilterWithoutEndDate;57@end58 59@interface CalDAVConcreteServerVersion : CalDAVServerVersion {60}61@end62 63@interface CalendarServerVersion : CalDAVConcreteServerVersion64@end65 66@implementation CalDAVServerVersion67@synthesize supportsTimeRangeFilterWithoutEndDate=_supportsTimeRangeFilterWithoutEndDate;68@end69 70@implementation CalendarServerVersion71-(BOOL)supportsTimeRangeFilterWithoutEndDate {72 return 0;73}74@end75 76@interface CDBModifyRecordsOperation : NSObject77@property (nonatomic, assign) BOOL atomic;78@end79 80@class NSString;81 82@implementation CDBModifyRecordsOperation83- (void)setAtomic:(BOOL)atomic {84 if (atomic == __objc_yes) {85 NSString *recordZoneID = 0;86 }87 _atomic = atomic;88}89@end90 91@interface GATTOperation : NSObject {92 long operation;93}94@property(assign) long operation;95@end96 97@implementation GATTOperation98@synthesize operation;99+ (id) operation {100 return 0;101}102@end103 104@interface Radar15727327 : NSObject105@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@end110 111@implementation Radar15727327112@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@end121 122@interface I1123@property (readonly) int p1;124@property (readonly) int p2; // expected-note {{property declared here}}125@end126 127@implementation I1128@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@end145 146@protocol MyProtocol147@property (nonatomic, readonly) int myProperty;148@end149 150@interface MyFirstClass : NSObject <MyProtocol>151@end152 153@interface MySecondClass : NSObject <MyProtocol>154@end155 156@implementation MyFirstClass157@synthesize myProperty;158@end159 160@implementation MySecondClass161@dynamic myProperty;162-(int)myProperty // should not warn; property is dynamic163{164 return 0;165}166@end167 168@class NSURL;169 170@protocol MCCIDURLProtocolDataProvider171@required172@property(strong, atomic, readonly) NSURL *cidURL;173@property(strong, atomic, readonly) NSURL *cidURL1; // expected-note {{property declared here}}174@end175 176@interface UnrelatedClass : NSObject <MCCIDURLProtocolDataProvider>177@end178 179@implementation UnrelatedClass180@synthesize cidURL = _cidURL;181@synthesize cidURL1 = _cidURL1;182@end183 184@interface MUIWebAttachmentController : NSObject <MCCIDURLProtocolDataProvider>185@end186 187 188@implementation MUIWebAttachmentController189- (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@end197