]> granicus.if.org Git - clang/commitdiff
Lookup selector in protocol list of qualified objc type
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 9 Mar 2011 20:18:06 +0000 (20:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 9 Mar 2011 20:18:06 +0000 (20:18 +0000)
to avoid a bogus warning. // rdar:// 9072298

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127355 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaExprObjC.cpp
lib/Sema/SemaStmt.cpp
test/SemaObjC/foreach.m

index f7d9e80c7bc629042b7fbdcfa62f228d451ef608..b3761f36dac5bf6c73fbd0780667164023b949fa 100644 (file)
@@ -4551,6 +4551,9 @@ public:
                                            ObjCInterfaceDecl *CDecl);
   ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
                                               ObjCInterfaceDecl *ClassDecl);
+  ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
+                                              const ObjCObjectPointerType *OPT,
+                                              bool IsInstance);
 
   ExprResult
   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
index 3d8d42fa001ee5691cf8dc3639c388bd2381e966..5826f296c1fac6f3dea282d0eeda0aa7fbe73c94 100644 (file)
@@ -381,6 +381,23 @@ ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel,
   return Method;
 }
 
+/// LookupMethodInQualifiedType - Lookups up a method in protocol qualifier 
+/// list of a qualified objective pointer type.
+ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel,
+                                              const ObjCObjectPointerType *OPT,
+                                              bool Instance)
+{
+  ObjCMethodDecl *MD = 0;
+  for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
+       E = OPT->qual_end(); I != E; ++I) {
+    ObjCProtocolDecl *PROTO = (*I);
+    if ((MD = PROTO->lookupMethod(Sel, Instance))) {
+      return MD;
+    }
+  }
+  return 0;
+}
+
 /// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
 /// objective C interface.  This is a property reference expression.
 ExprResult Sema::
index ca37df943890150d8c137c49d3e04c02c2c3be75..dae6bce6266cff8e78065703d4e3d79d7904c10f 100644 (file)
@@ -991,7 +991,8 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
       Selector CSelector = Context.Selectors.getSelector(3, &KeyIdents[0]);
       if (ObjCInterfaceDecl *IDecl = OPT->getInterfaceDecl()) {
         if (!IDecl->isForwardDecl() &&
-            !IDecl->lookupInstanceMethod(CSelector)) {
+            !IDecl->lookupInstanceMethod(CSelector) &&
+            !LookupMethodInQualifiedType(CSelector, OPT, true)) {
           // Must further look into private implementation methods.
           if (!LookupPrivateInstanceMethod(CSelector, IDecl))
             Diag(ForLoc, diag::warn_collection_expr_type)
index 0f7fd9eea9922c4e94adebbb27f389a1f5df7eb7..c865374e61affa9dab7729257f97617a69f523fc 100644 (file)
@@ -16,3 +16,33 @@ void f(NSArray *a) {
   for (id thisKey in keys);
   for (id thisKey in keys);
 }
+
+/* // rdar://9072298 */
+@protocol NSObject @end
+
+@interface NSObject <NSObject> {
+    Class isa;
+}
+@end
+
+typedef struct {
+    unsigned long state;
+    id *itemsPtr;
+    unsigned long *mutationsPtr;
+    unsigned long extra[5];
+} NSFastEnumerationState;
+
+@protocol NSFastEnumeration
+
+- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
+
+@end
+
+int main ()
+{
+ NSObject<NSFastEnumeration>* collection = ((void*)0);
+ for (id thing in collection) { }
+
+ return 0;
+}
+