objc-arc: 'readonly' property of retainable object
type is strong by default too. // rdar://10410903
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144118 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 46b2a08..4933f00 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -1770,13 +1770,12 @@
ObjCDeclSpec::DQ_PR_unsafe_unretained |
ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong |
ObjCDeclSpec::DQ_PR_weak)) &&
- !(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
PropertyTy->isObjCObjectPointerType()) {
if (getLangOptions().ObjCAutoRefCount)
// With arc, @property definitions should default to (strong) when
- // not specified
+ // not specified; including when property is 'readonly'.
PropertyDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
- else {
+ else if (!(Attributes & ObjCDeclSpec::DQ_PR_readonly)) {
// Skip this warning in gc-only mode.
if (getLangOptions().getGC() != LangOptions::GCOnly)
Diag(Loc, diag::warn_objc_property_no_assignment_attribute);
diff --git a/test/ARCMT/assign-prop-with-arc-runtime.m b/test/ARCMT/assign-prop-with-arc-runtime.m
index 8408a18..8845010 100644
--- a/test/ARCMT/assign-prop-with-arc-runtime.m
+++ b/test/ARCMT/assign-prop-with-arc-runtime.m
@@ -14,7 +14,8 @@
@class Forw;
@interface Foo : NSObject {
- Foo *x, *w, *q1, *q2;
+ Foo *w, *q1, *q2;
+ __weak Foo *x;
WeakOptOut *oo;
BadClassForWeak bcw;
id not_safe1;
@@ -22,7 +23,7 @@
Forw *not_safe3;
Foo *assign_plus1;
}
-@property (readonly) Foo *x;
+@property (readonly) __weak Foo *x;
@property (assign) Foo *w;
@property Foo *q1, *q2;
@property (assign) WeakOptOut *oo;
diff --git a/test/ARCMT/assign-prop-with-arc-runtime.m.result b/test/ARCMT/assign-prop-with-arc-runtime.m.result
index e6070a8..2c67f18 100644
--- a/test/ARCMT/assign-prop-with-arc-runtime.m.result
+++ b/test/ARCMT/assign-prop-with-arc-runtime.m.result
@@ -14,7 +14,8 @@
@class Forw;
@interface Foo : NSObject {
- Foo *__weak x, *__weak w, *__weak q1, *__weak q2;
+ Foo *__weak w, *__weak q1, *__weak q2;
+ __weak Foo *x;
WeakOptOut *__unsafe_unretained oo;
BadClassForWeak __unsafe_unretained bcw;
id __unsafe_unretained not_safe1;
@@ -22,7 +23,7 @@
Forw *__unsafe_unretained not_safe3;
Foo *assign_plus1;
}
-@property (readonly) Foo *x;
+@property (readonly) __weak Foo *x;
@property (weak) Foo *w;
@property (weak) Foo *q1, *q2;
@property (unsafe_unretained) WeakOptOut *oo;
diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m
index d146d8f..c0393c4 100644
--- a/test/SemaObjC/arc.m
+++ b/test/SemaObjC/arc.m
@@ -502,18 +502,18 @@
id myProp2;
}
@property id x;
-@property (readonly) id ro; // expected-note {{declared here}}
+@property (readonly) id ro;
@property (readonly) id custom_ro;
@property int y;
-@property (readonly) id myProp1;
+@property (readonly) __weak id myProp1;
@property (readonly) id myProp2;
@property (readonly) __strong id myProp3;
@end
@implementation Test27
@synthesize x;
-@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
+@synthesize ro;
@synthesize y;
@synthesize myProp1 = _myProp1;