[cfe-commits] r71278 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/forward-class-receiver.m
Fariborz Jahanian
fjahanian at apple.com
Fri May 8 16:02:37 PDT 2009
Author: fjahanian
Date: Fri May 8 18:02:36 2009
New Revision: 71278
URL: http://llvm.org/viewvc/llvm-project?rev=71278&view=rev
Log:
Warn if forward class is used as a receiver.
Added:
cfe/trunk/test/SemaObjC/forward-class-receiver.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=71278&r1=71277&r2=71278&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 8 18:02:36 2009
@@ -1690,6 +1690,8 @@
// 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<
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=71278&r1=71277&r2=71278&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri May 8 18:02:36 2009
@@ -422,7 +422,15 @@
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)
Added: cfe/trunk/test/SemaObjC/forward-class-receiver.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/forward-class-receiver.m?rev=71278&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/forward-class-receiver.m (added)
+++ cfe/trunk/test/SemaObjC/forward-class-receiver.m Fri May 8 18:02:36 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+ at interface I
++ new;
+ at end
+Class isa;
+
+ at class NotKnown;
+
+void foo(NotKnown *n) {
+ [isa new];
+ [NotKnown new]; /* expected-warning {{receiver 'NotKnown' is a forward class and corresponding}} */
+}
More information about the cfe-commits
mailing list