[cfe-commits] r70987 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/inst-method-lookup-in-root.m
Fariborz Jahanian
fjahanian at apple.com
Tue May 5 11:34:54 PDT 2009
Author: fjahanian
Date: Tue May 5 13:34:37 2009
New Revision: 70987
URL: http://llvm.org/viewvc/llvm-project?rev=70987&view=rev
Log:
Issue a warning in odd case of instance method used
in a 'Class' receiver which is not a root instance
method.
Added:
cfe/trunk/test/SemaObjC/inst-method-lookup-in-root.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70987&r1=70986&r2=70987&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 5 13:34:37 2009
@@ -1096,6 +1096,8 @@
// Obj-c expressions
+def warn_root_inst_method_not_found : Warning<
+ "instance method %0 is being used on 'Class' which is not in the root class">;
def warn_class_method_not_found : Warning<
"method %objcclass0 not found (return type defaults to 'id')">;
def warn_inst_method_not_found : Warning<
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=70987&r1=70986&r2=70987&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue May 5 13:34:37 2009
@@ -529,8 +529,17 @@
if (!isSelfExpr(RExpr)) {
Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac,rbrac));
if (!Method) {
+ // If no class (factory) method was found, check if an _instance_
+ // method of the same name exists in the root class only.
Method = LookupInstanceMethodInGlobalPool(
Sel, SourceRange(lbrac,rbrac));
+ if (Method)
+ if (const ObjCInterfaceDecl *ID =
+ dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext())) {
+ if (ID->getSuperClass())
+ Diag(lbrac, diag::warn_root_inst_method_not_found)
+ << Sel << SourceRange(lbrac, rbrac);
+ }
}
}
}
Added: cfe/trunk/test/SemaObjC/inst-method-lookup-in-root.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/inst-method-lookup-in-root.m?rev=70987&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/inst-method-lookup-in-root.m (added)
+++ cfe/trunk/test/SemaObjC/inst-method-lookup-in-root.m Tue May 5 13:34:37 2009
@@ -0,0 +1,27 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+ at protocol P
+- (id) inst_in_proto;
+ at end
+
+ at interface Object <P>
+- (id) inst_in_root;
+ at end
+
+ at interface Base
+ at end
+
+ at interface Derived: Base
+- (id)starboard;
+ at end
+
+void foo(void) {
+ Class receiver;
+
+ [Derived starboard]; // expected-warning {{method '+starboard' not found}}
+
+ [receiver starboard]; // expected-warning {{instance method 'starboard' is being used on 'Class'}}
+ [receiver inst_in_root]; // Ok!
+ [receiver inst_in_proto]; // Ok!
+}
+
More information about the cfe-commits
mailing list