diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-08 23:32:30 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-08 23:32:30 +0000 |
commit | 125643455953069b925b30d2e4ae5674063984ed (patch) | |
tree | 754e76c08669bc64993756ebea17d91bb866ace0 | |
parent | 799f3c13fbeacedda24549c41e72c07905208661 (diff) |
objective-C: don't issue bogus warning about
"auto-synthesized may not work correctly with 'nib' loader"
when 'readonly' property is redeclared 'readwrite' in class
extension. // rdar://13123861
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174775 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaObjCProperty.cpp | 42 | ||||
-rw-r--r-- | test/SemaObjC/iboutlet.m | 21 |
2 files changed, 51 insertions, 12 deletions
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index eea265ade1..da7b4729b1 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -839,22 +839,40 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, return 0; } } - if (Synthesize&& (PIkind & ObjCPropertyDecl::OBJC_PR_readonly) && property->hasAttr<IBOutletAttr>() && !AtLoc.isValid()) { - Diag(IC->getLocation(), diag::warn_auto_readonly_iboutlet_property); - Diag(property->getLocation(), diag::note_property_declare); - SourceLocation readonlyLoc; - if (LocPropertyAttribute(Context, "readonly", - property->getLParenLoc(), readonlyLoc)) { - SourceLocation endLoc = - readonlyLoc.getLocWithOffset(strlen("readonly")-1); - SourceRange ReadonlySourceRange(readonlyLoc, endLoc); - Diag(property->getLocation(), - diag::note_auto_readonly_iboutlet_fixup_suggest) << - FixItHint::CreateReplacement(ReadonlySourceRange, "readwrite"); + bool ReadWriteProperty = false; + // Search into the class extensions and see if 'readonly property is + // redeclared 'readwrite', then no warning is to be issued. + for (ObjCInterfaceDecl::known_extensions_iterator + Ext = IDecl->known_extensions_begin(), + ExtEnd = IDecl->known_extensions_end(); Ext != ExtEnd; ++Ext) { + DeclContext::lookup_result R = Ext->lookup(property->getDeclName()); + if (!R.empty()) + if (ObjCPropertyDecl *ExtProp = dyn_cast<ObjCPropertyDecl>(R[0])) { + PIkind = ExtProp->getPropertyAttributesAsWritten(); + if (PIkind & ObjCPropertyDecl::OBJC_PR_readwrite) { + ReadWriteProperty = true; + break; + } + } + } + + if (!ReadWriteProperty) { + Diag(IC->getLocation(), diag::warn_auto_readonly_iboutlet_property); + Diag(property->getLocation(), diag::note_property_declare); + SourceLocation readonlyLoc; + if (LocPropertyAttribute(Context, "readonly", + property->getLParenLoc(), readonlyLoc)) { + SourceLocation endLoc = + readonlyLoc.getLocWithOffset(strlen("readonly")-1); + SourceRange ReadonlySourceRange(readonlyLoc, endLoc); + Diag(property->getLocation(), + diag::note_auto_readonly_iboutlet_fixup_suggest) << + FixItHint::CreateReplacement(ReadonlySourceRange, "readwrite"); + } } } diff --git a/test/SemaObjC/iboutlet.m b/test/SemaObjC/iboutlet.m index a29915c393..9363749702 100644 --- a/test/SemaObjC/iboutlet.m +++ b/test/SemaObjC/iboutlet.m @@ -21,3 +21,24 @@ @implementation I // expected-warning 3 {{readonly IBOutlet property when auto-synthesized may not work correctly with 'nib' loader}} @end + + +// rdar://13123861 +@class UILabel; + +@interface NSObject @end + +@interface RKTFHView : NSObject +@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadOnly; // expected-note {{property declared here}} expected-note {{readonly IBOutlet property should be changed to be readwrite}} +@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite; +@property( readonly ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite; +@end + +@interface RKTFHView() +@property( readwrite ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite; +@property( readwrite ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite; +@end + +@implementation RKTFHView // expected-warning {{readonly IBOutlet property when auto-synthesized may not work correctly with 'nib' loader}} +@synthesize synthReadOnlyReadWrite=_synthReadOnlyReadWrite; +@end |