]> granicus.if.org Git - clang/commitdiff
obj-c++: allow the getter/setter to return/take parameters
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 15 Oct 2011 17:36:49 +0000 (17:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 15 Oct 2011 17:36:49 +0000 (17:36 +0000)
by reference. // rdar://10188258

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142075 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
lib/Sema/SemaObjCProperty.cpp
test/CodeGenObjCXX/property-object-reference.mm

index 170097cc59a9c60f7223745b5e22a2e09961e74b..60f84183fae8c2405387c2d69b00716cf3226426 100644 (file)
@@ -7264,13 +7264,14 @@ void Sema::ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS,
         return;
       }
     }
-  } else if (getLangOptions().ObjCAutoRefCount) {
+  } else {
     const ObjCMethodDecl *setter
       = PropRef->getExplicitProperty()->getSetterMethodDecl();
     if (setter) {
       ObjCMethodDecl::param_const_iterator P = setter->param_begin();
       LHSTy = (*P)->getType();
-      Consumed = (*P)->hasAttr<NSConsumedAttr>();
+      if (getLangOptions().ObjCAutoRefCount)
+        Consumed = (*P)->hasAttr<NSConsumedAttr>();
     }
   }
 
@@ -7285,6 +7286,7 @@ void Sema::ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS,
         checkRetainCycles(const_cast<Expr*>(PropRef->getBase()), RHS.get());
     }
   }
+  LHSTy = LHSTy.getNonReferenceType();
 }
   
 
index 751f553945cd370a927cfed22d469931c3226523..d35c01039c14fb5fb4048cfd215ad769f791b9eb 100644 (file)
@@ -948,7 +948,8 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
                                             ObjCMethodDecl *GetterMethod,
                                             SourceLocation Loc) {
   if (GetterMethod &&
-      GetterMethod->getResultType() != property->getType()) {
+      GetterMethod->getResultType().getNonReferenceType() 
+      != property->getType().getNonReferenceType()) {
     AssignConvertType result = Incompatible;
     if (property->getType()->isObjCObjectPointerType())
       result = CheckAssignmentConstraints(Loc, GetterMethod->getResultType(),
@@ -1510,7 +1511,8 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
       Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
     if (SetterMethod->param_size() != 1 ||
         !Context.hasSameUnqualifiedType(
-          (*SetterMethod->param_begin())->getType(), property->getType())) {
+          (*SetterMethod->param_begin())->getType().getNonReferenceType(), 
+          property->getType().getNonReferenceType())) {
       Diag(property->getLocation(),
            diag::warn_accessor_property_type_mismatch)
         << property->getDeclName()
index b87ce2303b5e2666201e002eeca25082daa3c34a..0bd8fb8b9ff260739c1e427f76d1b1398f06375a 100644 (file)
@@ -2,9 +2,14 @@
 // rdar://10188258
 
 struct Foo {int i;};
+static Foo gFoo;
+
 
 @interface ObjCTest  { }
 @property (nonatomic, readonly) Foo& FooRefProperty;
+@property (nonatomic) Foo  FooProperty;
+- (Foo &) FooProperty;
+- (void)setFooProperty : (Foo &) arg;
 @end
 
 
@@ -13,11 +18,18 @@ struct Foo {int i;};
 
 -(void) test {
     Foo& f = self.FooRefProperty;
+    Foo& f1 = self.FooProperty;
 }
+- (Foo &) FooProperty { return gFoo; }
+- (void)setFooProperty : (Foo &) arg {  };
 @end
 
 // CHECK: [[T0:%.*]] = load {{%.*}} [[S0:%.*]]
 // CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
 // CHECK:  [[T2:%.*]]  = bitcast {{%.*}} [[T0]] to i8*
 // CHECK:  @objc_msgSend
+// CHECK: [[R0:%.*]] = load {{%.*}} [[U0:%.*]]
+// CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
+// CHECK:  [[R2:%.*]]  = bitcast {{%.*}} [[R0]] to i8*
+// CHECK:  @objc_msgSend