[Objctive-C sema]. Do not do the unused-getter-return-value
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Feb 2015 23:49:44 +0000 (23:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Feb 2015 23:49:44 +0000 (23:49 +0000)
warning when property getter is used in direct method call
and return value of property is unused. rdar://19773512

llvm-svn: 229458

clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaObjC/unused.m

index e7b7f20..6f54008 100644 (file)
@@ -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;
index 4761c32..bc5c155 100644 (file)
@@ -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();
index 6ea3fe8..f31e470 100644 (file)
@@ -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
+