r197209 - Refine 'objc_protocol_requires_explicit_implementation' attribute to better handle indirect protocols.

Ted Kremenek kremenek at apple.com
Thu Dec 12 22:26:14 PST 2013


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))
+ at protocol ProtocolA
+ at required
+- (void)rlyeh;
+- (void)innsmouth;
+ at end
+
+ at protocol ProtocolB <ProtocolA>
+ at required
+- (void)dunwich;
+- (id)innsmouth;
+ at end
+
+ at protocol ProtocolC
+ at required
+- (void)rlyeh;
+- (void)innsmouth;
+- (void)dunwich;
+ at end
+
+ at interface MyObject <ProtocolC>
+ at end
+
+ at interface MyLovecraft <ProtocolA>
+ at end
+
+ at interface MyShoggoth : MyLovecraft <ProtocolB>
+ at end
+
+ at implementation MyObject
+- (void)innsmouth {}
+- (void)rlyeh {}
+- (void)dunwich {}
+ at end
+
+ at implementation MyLovecraft
+- (void)innsmouth {}
+- (void)rlyeh {}
+ at end
+
+ at implementation MyShoggoth
+- (void)dunwich {}
+ at end
+





More information about the cfe-commits mailing list