]> granicus.if.org Git - clang/commitdiff
Objective-C. When multiple nullary selectors are found in
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 27 Aug 2014 16:38:47 +0000 (16:38 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 27 Aug 2014 16:38:47 +0000 (16:38 +0000)
global pool in the course of method selection for
a messaging expression, select one with the most general
return type of 'id'. This is to remove type-mismatch
warning (which is useless) as result of random selection of
method with more restrictive return type. rdar://18095772

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

lib/Sema/SemaOverload.cpp
test/SemaObjC/resolve-method-in-global-pool.m

index 7bc42bfe9cb6496a2f4c5e608b2818fa0d0ba1b8..95b1dc090626bfc09e12fe36422c9f4779da7c15 100644 (file)
@@ -5743,10 +5743,20 @@ ObjCMethodDecl *Sema::SelectBestMethod(Selector Sel, MultiExprArg Args,
           break;
         }
       }
-    } else
+    } else {
       // Check for extra arguments to non-variadic methods.
       if (Args.size() != NumNamedArgs)
         Match = false;
+      else if (Match && NumNamedArgs == 0 && Methods.size() > 1) {
+        // Special case when selectors have no argument. In this case, select
+        // one with the most general result type of 'id'.
+        for (unsigned b = 0, e = Methods.size(); b < e; b++) {
+          QualType ReturnT = Methods[b]->getReturnType();
+          if (ReturnT->isObjCIdType())
+            return Methods[b];
+        }
+      }
+    }
 
     if (Match)
       return Method;
index 2c5dde4cba9ac121e8c2368b05b652225f2850b2..523856d663f63ed4d45d7d96fa2c0c2242ad776c 100644 (file)
 void func( Class c, float g ) {
     [c clsMethod: &g];
 }
+
+// rdar://18095772
+@protocol NSKeyedArchiverDelegate @end
+
+@interface NSKeyedArchiver
+@property (assign) id <NSKeyedArchiverDelegate> delegate;
+@end
+
+@interface NSConnection
+@property (assign) id delegate;
+@end
+
+extern id NSApp;
+
+@interface AppDelegate
+@end
+
+AppDelegate* GetDelegate()
+{
+    return [NSApp delegate];
+}