[Objctive-C sema]. Do not do the unused-getter-return-value
warning when property getter is used in direct method call and return value of property is unused. rdar://19773512 llvm-svn: 229458
This commit is contained in:
parent
5cedafb8cd
commit
b0553e21cc
|
@ -2238,9 +2238,7 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
|
|||
}
|
||||
|
||||
if (const ObjCMethodDecl *MD = ME->getMethodDecl())
|
||||
if (MD->hasAttr<WarnUnusedResultAttr>() ||
|
||||
(MD->isPropertyAccessor() && !MD->getReturnType()->isVoidType() &&
|
||||
!ME->getReceiverType()->isObjCIdType())) {
|
||||
if (MD->hasAttr<WarnUnusedResultAttr>()) {
|
||||
WarnE = this;
|
||||
Loc = getExprLoc();
|
||||
return true;
|
||||
|
|
|
@ -265,10 +265,6 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
|
|||
Diag(Loc, diag::warn_unused_result) << R1 << R2;
|
||||
return;
|
||||
}
|
||||
if (MD->isPropertyAccessor()) {
|
||||
Diag(Loc, diag::warn_unused_property_expr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) {
|
||||
const Expr *Source = POE->getSyntacticForm();
|
||||
|
|
|
@ -91,8 +91,7 @@ void rdar15596883(id x) {
|
|||
|
||||
void test3(PropertyObject *o)
|
||||
{
|
||||
[o length]; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
||||
(void)[o length];
|
||||
[o length]; // No warning. property name used in direct method call.
|
||||
}
|
||||
|
||||
void test4(id o)
|
||||
|
@ -102,5 +101,30 @@ void test4(id o)
|
|||
|
||||
void test5(id <P> p)
|
||||
{
|
||||
[p property]; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
||||
[p property]; // No warning. property name used in direct method call.
|
||||
}
|
||||
|
||||
// rdar://19773512
|
||||
@interface Model
|
||||
@property (nonatomic, retain, setter=setOrCreateGroup:, getter=getOrCreateGroup) id group;
|
||||
@end
|
||||
|
||||
@implementation Model {
|
||||
id _group;
|
||||
}
|
||||
- (void)method {
|
||||
[self getOrCreateGroup];
|
||||
self.getOrCreateGroup; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
||||
self.group; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
||||
self.group = (void*)0;
|
||||
[self setOrCreateGroup : ((void*)0)];
|
||||
|
||||
}
|
||||
- (id)getOrCreateGroup {
|
||||
if (!_group) {
|
||||
_group = @"group";
|
||||
}
|
||||
return _group;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in New Issue