Author: kremenek
Date: Fri Dec 13 00:26:14 2013
New Revision: 197209
URL: http://llvm.org/viewvc/llvm-project?rev=197209&view=rev
Log:
Refine 'objc_protocol_requires_explicit_implementation' attribute to better
handle indirect protocols.
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=197209&r1=197208&r2=197209&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Dec 13 00:26:14 2013
@@ -1641,7 +1641,8 @@ static void CheckProtocolMethodDefs(Sema
bool& IncompleteImpl,
const Sema::SelectorSet &InsMap,
const Sema::SelectorSet &ClsMap,
- ObjCContainerDecl *CDecl) {
+ ObjCContainerDecl *CDecl,
+ bool isExplicitProtocol = true) {
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
ObjCInterfaceDecl *IDecl = C ? C->getClassInterface()
: dyn_cast<ObjCInterfaceDecl>(CDecl);
@@ -1674,7 +1675,7 @@ static void CheckProtocolMethodDefs(Sema
// 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<ObjCExplicitProtocolImplAttr>())
+ if (isExplicitProtocol && PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
Super = NULL;
// check unimplemented instance methods.
@@ -1744,7 +1745,7 @@ static void CheckProtocolMethodDefs(Sema
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
Modified: cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m?rev=197209&r1=197208&r2=197209&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m (original)
+++ cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m Fri Dec 13
00:26:14 2013
@@ -54,3 +54,49 @@ __attribute__((objc_protocol_requires_ex
__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 <ProtocolA>
+@required
+- (void)dunwich;
+- (id)innsmouth;
+@end
+
+@protocol ProtocolC
+@required
+- (void)rlyeh;
+- (void)innsmouth;
+- (void)dunwich;
+@end
+
+@interface MyObject <ProtocolC>
+@end
+
+@interface MyLovecraft <ProtocolA>
+@end
+
+@interface MyShoggoth : MyLovecraft <ProtocolB>
+@end
+
+@implementation MyObject
+- (void)innsmouth {}
+- (void)rlyeh {}
+- (void)dunwich {}
+@end
+
+@implementation MyLovecraft
+- (void)innsmouth {}
+- (void)rlyeh {}
+@end
+
+@implementation MyShoggoth
+- (void)dunwich {}
+@end
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits