From c33f25bf5341d19be05bcf64848445d9931c2be1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 13 Dec 2013 06:26:14 +0000 Subject: [PATCH] Refine 'objc_protocol_requires_explicit_implementation' attribute to better handle indirect protocols. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197209 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 7 +-- .../SemaObjC/protocols-suppress-conformance.m | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 1aa36ca678..9f50a207c1 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1641,7 +1641,8 @@ static void CheckProtocolMethodDefs(Sema &S, bool& IncompleteImpl, const Sema::SelectorSet &InsMap, const Sema::SelectorSet &ClsMap, - ObjCContainerDecl *CDecl) { + ObjCContainerDecl *CDecl, + bool isExplicitProtocol = true) { ObjCCategoryDecl *C = dyn_cast(CDecl); ObjCInterfaceDecl *IDecl = C ? C->getClassInterface() : dyn_cast(CDecl); @@ -1674,7 +1675,7 @@ static void CheckProtocolMethodDefs(Sema &S, // the method was implemented by a base class or an inherited // protocol. This lookup is slow, but occurs rarely in correct code // and otherwise would terminate in a warning. - if (PDecl->hasAttr()) + if (isExplicitProtocol && PDecl->hasAttr()) Super = NULL; // check unimplemented instance methods. @@ -1744,7 +1745,7 @@ static void CheckProtocolMethodDefs(Sema &S, for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), E = PDecl->protocol_end(); PI != E; ++PI) CheckProtocolMethodDefs(S, ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap, - CDecl); + CDecl, /* isExplicitProtocl */ false); } /// MatchAllMethodDeclarations - Check methods declared in interface diff --git a/test/SemaObjC/protocols-suppress-conformance.m b/test/SemaObjC/protocols-suppress-conformance.m index f62b285175..e5fe1036bf 100644 --- a/test/SemaObjC/protocols-suppress-conformance.m +++ b/test/SemaObjC/protocols-suppress-conformance.m @@ -54,3 +54,49 @@ __attribute__((objc_protocol_requires_explicit_implementation)) // expected-erro __attribute__((objc_protocol_requires_explicit_implementation)) // expected-error {{attribute only applies to Objective-C protocols}} int x; +// Test that inherited protocols with the attribute +// are treated properly. +__attribute__((objc_protocol_requires_explicit_implementation)) +@protocol ProtocolA +@required +- (void)rlyeh; +- (void)innsmouth; +@end + +@protocol ProtocolB +@required +- (void)dunwich; +- (id)innsmouth; +@end + +@protocol ProtocolC +@required +- (void)rlyeh; +- (void)innsmouth; +- (void)dunwich; +@end + +@interface MyObject +@end + +@interface MyLovecraft +@end + +@interface MyShoggoth : MyLovecraft +@end + +@implementation MyObject +- (void)innsmouth {} +- (void)rlyeh {} +- (void)dunwich {} +@end + +@implementation MyLovecraft +- (void)innsmouth {} +- (void)rlyeh {} +@end + +@implementation MyShoggoth +- (void)dunwich {} +@end + -- 2.50.1