Issue a warning in odd case of instance method used

in a 'Class' receiver which is not a root instance
method.

llvm-svn: 70987
This commit is contained in:
Fariborz Jahanian 2009-05-05 18:34:37 +00:00
parent a35aed567a
commit 3baaffba6b
3 changed files with 38 additions and 0 deletions

View File

@ -1096,6 +1096,8 @@ def ext_freestanding_complex : Extension<
// 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<

View File

@ -529,8 +529,17 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
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);
}
}
}
}

View File

@ -0,0 +1,27 @@
// RUN: clang-cc -fsyntax-only -verify %s
@protocol P
- (id) inst_in_proto;
@end
@interface Object <P>
- (id) inst_in_root;
@end
@interface Base
@end
@interface Derived: Base
- (id)starboard;
@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!
}