is unused (this is match behavior when property-dot syntax is used to
use same getter). rdar://
17514245
Patch by Anders Carlsson with minor refactoring by me.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213423
91177308-0d34-0410-b5e6-
96231b3b80d8
return true;
}
- const ObjCMethodDecl *MD = ME->getMethodDecl();
- if (MD && MD->hasAttr<WarnUnusedResultAttr>()) {
- WarnE = this;
- Loc = getExprLoc();
- return true;
- }
+ if (const ObjCMethodDecl *MD = ME->getMethodDecl())
+ if (MD->hasAttr<WarnUnusedResultAttr>() ||
+ (MD->isPropertyAccessor() && !MD->getReturnType()->isVoidType() &&
+ !ME->getReceiverType()->isObjCIdType())) {
+ WarnE = this;
+ Loc = getExprLoc();
+ return true;
+ }
+
return false;
}
return;
}
const ObjCMethodDecl *MD = ME->getMethodDecl();
- if (MD && MD->hasAttr<WarnUnusedResultAttr>()) {
- Diag(Loc, diag::warn_unused_result) << R1 << R2;
- return;
+ if (MD) {
+ if (MD->hasAttr<WarnUnusedResultAttr>()) {
+ 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();
(void)Subclass.classMethod;
// also okay
- [RootClass property];
- [Subclass property];
+ (void)[RootClass property];
+ (void)[Subclass property];
[RootClass method];
[Subclass method];
[RootClass classMethod];
return a ? x : p;
}
-void f8(int a, A<P0> *x, A *y) {
- [ (a ? x : y ) intProp ];
+int f8(int a, A<P0> *x, A *y) {
+ return [ (a ? x : y ) intProp ];
}
void f9(int a, A<P0> *x, A<P1> *y) {
void test(Foo *y, Bar *x, id<myProtocol> z) {
y.myProperty = 0; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}}
- [y myProperty]; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}}
+ (void)[y myProperty]; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}}
x.myProperty = 1; // no-warning
- [x myProperty]; // no-warning
+ (void)[x myProperty]; // no-warning
x.myProtocolProperty = 0; // no-warning
- [x myProtocolProperty]; // no-warning
- [z myProtocolProperty]; // expected-warning {{'myProtocolProperty' is deprecated: first deprecated in OS X 10.8}}
+ (void)[x myProtocolProperty]; // no-warning
+ (void)[z myProtocolProperty]; // expected-warning {{'myProtocolProperty' is deprecated: first deprecated in OS X 10.8}}
}
rdar15596883_foo();
}
+@interface PropertyObject : NSObject
+@property int length;
+@end
+
+@protocol P
+@property int property;
+@end
+
+void test3(PropertyObject *o)
+{
+ [o length]; // expected-warning {{property access result unused - getters should not be used for side effects}}
+ (void)[o length];
+}
+
+void test4(id o)
+{
+ [o length]; // No warning.
+}
+
+void test5(id <P> p)
+{
+ [p property]; // expected-warning {{property access result unused - getters should not be used for side effects}}
+}