Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f21a92d

Browse files
author
Fariborz Jahanian
committed
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
1 parent 4c11772 commit f21a92d

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/Sema/SemaObjCProperty.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1770,13 +1770,12 @@ void Sema::CheckObjCPropertyAttributes(Decl *PDecl,
17701770
ObjCDeclSpec::DQ_PR_unsafe_unretained |
17711771
ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong |
17721772
ObjCDeclSpec::DQ_PR_weak)) &&
1773-
!(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
17741773
PropertyTy->isObjCObjectPointerType()) {
17751774
if (getLangOptions().ObjCAutoRefCount)
17761775
// With arc, @property definitions should default to (strong) when
1777-
// not specified
1776+
// not specified; including when property is 'readonly'.
17781777
PropertyDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
1779-
else {
1778+
else if (!(Attributes & ObjCDeclSpec::DQ_PR_readonly)) {
17801779
// Skip this warning in gc-only mode.
17811780
if (getLangOptions().getGC() != LangOptions::GCOnly)
17821781
Diag(Loc, diag::warn_objc_property_no_assignment_attribute);

test/ARCMT/assign-prop-with-arc-runtime.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ @interface WeakOptOut
1414
@class Forw;
1515

1616
@interface Foo : NSObject {
17-
Foo *x, *w, *q1, *q2;
17+
Foo *w, *q1, *q2;
18+
__weak Foo *x;
1819
WeakOptOut *oo;
1920
BadClassForWeak bcw;
2021
id not_safe1;
2122
NSObject *not_safe2;
2223
Forw *not_safe3;
2324
Foo *assign_plus1;
2425
}
25-
@property (readonly) Foo *x;
26+
@property (readonly) __weak Foo *x;
2627
@property (assign) Foo *w;
2728
@property Foo *q1, *q2;
2829
@property (assign) WeakOptOut *oo;

test/ARCMT/assign-prop-with-arc-runtime.m.result

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ typedef _NSCachedAttributedString *BadClassForWeak;
1414
@class Forw;
1515

1616
@interface Foo : NSObject {
17-
Foo *__weak x, *__weak w, *__weak q1, *__weak q2;
17+
Foo *__weak w, *__weak q1, *__weak q2;
18+
__weak Foo *x;
1819
WeakOptOut *__unsafe_unretained oo;
1920
BadClassForWeak __unsafe_unretained bcw;
2021
id __unsafe_unretained not_safe1;
2122
NSObject *__unsafe_unretained not_safe2;
2223
Forw *__unsafe_unretained not_safe3;
2324
Foo *assign_plus1;
2425
}
25-
@property (readonly) Foo *x;
26+
@property (readonly) __weak Foo *x;
2627
@property (weak) Foo *w;
2728
@property (weak) Foo *q1, *q2;
2829
@property (unsafe_unretained) WeakOptOut *oo;

test/SemaObjC/arc.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,18 @@ @interface Test27 {
502502
id myProp2;
503503
}
504504
@property id x;
505-
@property (readonly) id ro; // expected-note {{declared here}}
505+
@property (readonly) id ro;
506506
@property (readonly) id custom_ro;
507507
@property int y;
508508

509-
@property (readonly) id myProp1;
509+
@property (readonly) __weak id myProp1;
510510
@property (readonly) id myProp2;
511511
@property (readonly) __strong id myProp3;
512512
@end
513513

514514
@implementation Test27
515515
@synthesize x;
516-
@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
516+
@synthesize ro;
517517
@synthesize y;
518518

519519
@synthesize myProp1 = _myProp1;

0 commit comments

Comments
 (0)