From 3fa9b8e2c45eb398661c35f8cdc1f97492187b87 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 5 Mar 2014 23:44:00 +0000 Subject: [PATCH] Objective-C. Suppress the warning for auto synthesis of property not synthesizing protocol properties if class's super class implements them. // rdar://16089191 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203028 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaObjCProperty.cpp | 32 ++++++++++++++++++++++++---- test/SemaObjC/default-synthesize-3.m | 32 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index ce8f9d1515..c96fcbed53 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1534,6 +1534,26 @@ Sema::IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, return false; } +static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl, + ObjCPropertyDecl *Prop) { + bool SuperClassImplementsGetter = false; + bool SuperClassImplementsSetter = false; + if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly) + SuperClassImplementsSetter = true; + + while (IDecl->getSuperClass()) { + ObjCInterfaceDecl *SDecl = IDecl->getSuperClass(); + if (!SuperClassImplementsGetter && SDecl->getInstanceMethod(Prop->getGetterName())) + SuperClassImplementsGetter = true; + + if (!SuperClassImplementsSetter && SDecl->getInstanceMethod(Prop->getSetterName())) + SuperClassImplementsSetter = true; + if (SuperClassImplementsGetter && SuperClassImplementsSetter) + return true; + IDecl = IDecl->getSuperClass(); + } + return false; +} /// \brief Default synthesizes all properties which must be synthesized /// in class's \@implementation. @@ -1590,10 +1610,14 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, if (ObjCProtocolDecl *Proto = dyn_cast(Prop->getDeclContext())) { // We won't auto-synthesize properties declared in protocols. - Diag(IMPDecl->getLocation(), - diag::warn_auto_synthesizing_protocol_property) - << Prop << Proto; - Diag(Prop->getLocation(), diag::note_property_declare); + // Suppress the warning if class's superclass implements property's + // getter and implements property's setter (if readwrite property). + if (!SuperClassImplementsProperty(IDecl, Prop)) { + Diag(IMPDecl->getLocation(), + diag::warn_auto_synthesizing_protocol_property) + << Prop << Proto; + Diag(Prop->getLocation(), diag::note_property_declare); + } continue; } diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m index e409d21692..9406543169 100644 --- a/test/SemaObjC/default-synthesize-3.m +++ b/test/SemaObjC/default-synthesize-3.m @@ -181,3 +181,35 @@ typedef NSObject FooObject; @implementation Fail // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} @end +// rdar://16089191 +@class NSURL; + +@interface Root +- (void)setFileURL : (NSURL *) arg; +- (void)setFile : (NSURL *) arg; +- (NSURL *)fileSys; +- (void)setFileSys : (NSURL *) arg; +- (NSURL *)fileKerl; +@end + +@interface SuperClass : Root +- (NSURL *)fileURL; +- (NSURL *)file; +- (NSURL *)fileLog; +- (void)setFileLog : (NSURL *) arg; +- (void)setFileKerl : (NSURL *) arg; +@end + +@protocol r16089191Protocol +@property (readonly) NSURL *fileURL; +@property (copy) NSURL *file; +@property (copy) NSURL *fileSys; +@property (copy) NSURL *fileLog; +@property (copy) NSURL *fileKerl; +@end + +@interface SubClass : SuperClass +@end + +@implementation SubClass +@end -- 2.40.0