Skip to content

Commit

Permalink
Warn if forward class is used as a receiver.
Browse files Browse the repository at this point in the history
llvm-svn: 71278
  • Loading branch information
Fariborz Jahanian committed May 8, 2009
1 parent 18f026a commit 1bd844d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,8 @@ def err_collection_expr_type : Error<

// Type
def ext_invalid_sign_spec : Extension<"'%0' cannot be signed or unsigned">;
def warn_receiver_forward_class : Warning<
"receiver %0 is a forward class and corresponding @interface may not exist">;
def warn_missing_declspec : Warning<
"declaration specifier missing, defaulting to 'int'">;
def warn_missing_type_specifier : Warning<
Expand Down
10 changes: 9 additions & 1 deletion clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,15 @@ Sema::ExprResult Sema::ActOnClassMessage(
assert(ClassDecl && "missing interface declaration");
ObjCMethodDecl *Method = 0;
QualType returnType;
Method = ClassDecl->lookupClassMethod(Context, Sel);
if (ClassDecl->isForwardDecl()) {
// A forward class used in messaging is tread as a 'Class'
Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac,rbrac));
if (Method)
Diag(lbrac, diag::warn_receiver_forward_class)
<< ClassDecl->getDeclName();
}
if (!Method)
Method = ClassDecl->lookupClassMethod(Context, Sel);

// If we have an implementation in scope, check "private" methods.
if (!Method)
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaObjC/forward-class-receiver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: clang-cc -fsyntax-only -verify %s

@interface I
+ new;
@end
Class isa;

@class NotKnown;

void foo(NotKnown *n) {
[isa new];
[NotKnown new]; /* expected-warning {{receiver 'NotKnown' is a forward class and corresponding}} */
}

0 comments on commit 1bd844d

Please sign in to comment.