/// \brief Indicates if the method was a definition but its body was skipped.
unsigned HasSkippedBody : 1;
+
+ /// \brief True if method body makes a method call.
+ unsigned MethodCallsMethod : 1;
// Result type of this method.
QualType MethodDeclType;
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
RelatedResultType(HasRelatedResultType),
SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
- MethodDeclType(T), ResultTInfo(ResultTInfo),
+ MethodCallsMethod(0), MethodDeclType(T), ResultTInfo(ResultTInfo),
ParamsAndSelLocs(0), NumParams(0),
DeclEndLoc(endLoc), Body(), SelfDecl(0), CmdDecl(0) {
setImplicit(isImplicitlyDeclared);
bool hasSkippedBody() const { return HasSkippedBody; }
void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
+ bool getMethodCallsMethod() const { return MethodCallsMethod; }
+ void setMethodCallsMethod(bool val = true) { MethodCallsMethod = val; }
+
/// \brief Returns the property associated with this method's selector.
///
/// Note that even if this particular method is not marked as a property
const ObjCPropertyDecl *PDecl;
const ObjCIvarDecl *IV = GetIvarBackingPropertyAccessor(CurMethod, PDecl);
if (IV && !IV->getBackingIvarReferencedInAccessor()) {
- Diag(getCurMethodDecl()->getLocation(), diag::warn_unused_property_backing_ivar)
- << IV->getDeclName();
- Diag(PDecl->getLocation(), diag::note_property_declare);
+ // Do not issue this warning if backing ivar is used somewhere and accessor
+ // implementation makes a call to a method. This is to prevent false positive in
+ // some corner cases.
+ if (!IV->isReferenced() || !CurMethod->getMethodCallsMethod()) {
+ Diag(getCurMethodDecl()->getLocation(), diag::warn_unused_property_backing_ivar)
+ << IV->getDeclName();
+ Diag(PDecl->getLocation(), diag::note_property_declare);
+ }
}
}
}
}
}
-
+ if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
+ CurMeth->setMethodCallsMethod(true);
+
return MaybeBindToTemporary(Result);
}
MD->setDefined(Record[Idx++]);
MD->IsOverriding = Record[Idx++];
MD->HasSkippedBody = Record[Idx++];
+ MD->MethodCallsMethod = Record[Idx++];
MD->IsRedeclaration = Record[Idx++];
MD->HasRedeclaration = Record[Idx++];
Record.push_back(D->isDefined());
Record.push_back(D->IsOverriding);
Record.push_back(D->HasSkippedBody);
+ Record.push_back(D->MethodCallsMethod);
Record.push_back(D->IsRedeclaration);
Record.push_back(D->HasRedeclaration);
return 0;
}
@end
+
+// rdar://15727327
+@interface Radar15727327 : NSObject
+@property (assign, readonly) long p;
+@property (assign) long q; // expected-note 2 {{property declared here}}
+@property (assign, readonly) long r; // expected-note {{property declared here}}
+- (long)Meth;
+@end
+
+@implementation Radar15727327
+@synthesize p;
+@synthesize q;
+@synthesize r;
+- (long)Meth { return p; }
+- (long) p { [self Meth]; return 0; }
+- (long) q { return 0; } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}}
+- (void) setQ : (long) val { } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}}
+- (long) r { [self Meth]; return p; } // expected-warning {{ivar 'r' which backs the property is not referenced in this property's accessor}}
+@end
+