Author: fjahanian
Date: Wed Aug 27 11:38:47 2014
New Revision: 216560

URL: http://llvm.org/viewvc/llvm-project?rev=216560&view=rev
Log:
Objective-C. When multiple nullary selectors are found in
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

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaObjC/resolve-method-in-global-pool.m

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=216560&r1=216559&r2=216560&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Aug 27 11:38:47 2014
@@ -5743,10 +5743,20 @@ ObjCMethodDecl *Sema::SelectBestMethod(S
           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;

Modified: cfe/trunk/test/SemaObjC/resolve-method-in-global-pool.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/resolve-method-in-global-pool.m?rev=216560&r1=216559&r2=216560&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/resolve-method-in-global-pool.m (original)
+++ cfe/trunk/test/SemaObjC/resolve-method-in-global-pool.m Wed Aug 27 11:38:47 
2014
@@ -40,3 +40,24 @@
 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];
+}


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to