]> granicus.if.org Git - clang/commitdiff
Implement an important missing warning when a selector
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Mar 2009 22:19:15 +0000 (22:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Mar 2009 22:19:15 +0000 (22:19 +0000)
is searched for in the global pool. It already uncovered
a clang bug in message selection.

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

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaExprObjC.cpp
test/SemaObjC/conditional-expr.m
test/SemaObjC/warn-selector-selection.m [new file with mode: 0644]

index f1495a2ef412206c0d653a310d825a6add5871b5..6c635dae583cc83dfdaa85a13b0c849f9c23429f 100644 (file)
@@ -1454,3 +1454,5 @@ DIAG(error_private_ivar_access, ERROR,
      "instance variable %0 is private")
 DIAG(error_protected_ivar_access, ERROR,
      "instance variable %0 is protected")
+DIAG(warn_maynot_respond, WARNING,
+     "%0  may not respond to %1")
index 8b452af9e85b7e5bdf2ce33e2d8fc7da23fbacc8..39a89d6d9429f12e69bf1ab732bdf8d49fab5d0a 100644 (file)
@@ -450,16 +450,28 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
     }
     if (!Method) {
       // If we have an implementation in scope, check "private" methods.
-      if (ClassDecl)
+      if (ClassDecl) {
         if (ObjCImplementationDecl *ImpDecl = 
               ObjCImplementations[ClassDecl->getIdentifier()])
           Method = ImpDecl->getInstanceMethod(Sel);
-          // If we still haven't found a method, look in the global pool. This
-          // behavior isn't very desirable, however we need it for GCC
-          // compatibility. FIXME: should we deviate??
-          if (!Method && OCIType->qual_empty())
-            Method = LookupInstanceMethodInGlobalPool(
-                                 Sel, SourceRange(lbrac,rbrac));
+        // Look through local category implementations associated with the class.
+        if (!Method) {
+          for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
+            if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
+              Method = ObjCCategoryImpls[i]->getInstanceMethod(Sel);
+          }
+        }
+      }
+      // If we still haven't found a method, look in the global pool. This
+      // behavior isn't very desirable, however we need it for GCC
+      // compatibility. FIXME: should we deviate??
+      if (!Method && OCIType->qual_empty()) {
+        Method = LookupInstanceMethodInGlobalPool(
+                             Sel, SourceRange(lbrac,rbrac));
+        if (Method && !OCIType->getDecl()->isForwardDecl())
+          Diag(lbrac, diag::warn_maynot_respond) 
+            << OCIType->getDecl()->getIdentifier()->getName() << Sel;
+      }
     }
     if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
       return true;
index c607178a57cd51f292e0ebee30bf59ecdf8b504e..76656717e14ba889c641bd37521cf6243c581c72 100644 (file)
@@ -36,7 +36,7 @@
 // No @interface declaration for DTFilterOutputStream3
 @implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}}
 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
-  id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
+  id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{DTFilterOutputStream3  may not respond to 'nextOutputStream'}}
   // GCC warns about both of these as well (no errors).
   self = nextOutputStream; // expected-warning {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream3 *'}}
   return nextOutputStream ? nextOutputStream : self;
diff --git a/test/SemaObjC/warn-selector-selection.m b/test/SemaObjC/warn-selector-selection.m
new file mode 100644 (file)
index 0000000..777666d
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface Object 
+- (void)foo;
+@end
+
+@interface Class1
+- (void)setWindow:(Object *)wdw;
+@end
+
+void foo(void) {
+  Object *obj;
+  [obj setWindow:0]; // expected-warning{{Object  may not respond to 'setWindow:'}}
+}