[cfe-commits] r125699 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/property-missing.m

Fariborz Jahanian fjahanian at apple.com
Wed Feb 16 17:26:14 PST 2011


Author: fjahanian
Date: Wed Feb 16 19:26:14 2011
New Revision: 125699

URL: http://llvm.org/viewvc/llvm-project?rev=125699&view=rev
Log:
Improve diagnostics when property names an object type of
a forward class. // rdar://8851803

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/property-missing.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=125699&r1=125698&r2=125699&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 16 19:26:14 2011
@@ -2567,6 +2567,8 @@
   "expected getter method not found on object of type %0">;
 def err_property_not_found_forward_class : Error<
   "property %0 cannot be found in forward class object %1">;
+def err_property_not_as_forward_class : Error<
+  "property %0 names an object of forward class type in class object %1">;
 def note_forward_class : Note<
   "forward class is declared here">;
 def err_duplicate_property : Error<

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=125699&r1=125698&r2=125699&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Feb 16 19:26:14 2011
@@ -520,6 +520,22 @@
     return HandleExprPropertyRefExpr(OPT, BaseExpr, TypoResult, MemberLoc,
                                      SuperLoc, SuperType, Super);
   }
+  ObjCInterfaceDecl *ClassDeclared;
+  if (ObjCIvarDecl *Ivar = 
+      IFace->lookupInstanceVariable(Member, ClassDeclared)) {
+    QualType T = Ivar->getType();
+    if (const ObjCObjectPointerType * OBJPT = 
+        T->getAsObjCInterfacePointerType()) {
+      const ObjCInterfaceType *IFaceT = OBJPT->getInterfaceType();
+      if (ObjCInterfaceDecl *IFace = IFaceT->getDecl())
+        if (IFace->isForwardDecl()) {
+          Diag(MemberLoc, diag::err_property_not_as_forward_class)
+          << MemberName << QualType(OPT, 0);
+          Diag(IFace->getLocation(), diag::note_forward_class);
+          return ExprError();
+        }
+    }
+  }
   
   Diag(MemberLoc, diag::err_property_not_found)
     << MemberName << QualType(OPT, 0);

Modified: cfe/trunk/test/SemaObjC/property-missing.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-missing.m?rev=125699&r1=125698&r2=125699&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-missing.m (original)
+++ cfe/trunk/test/SemaObjC/property-missing.m Wed Feb 16 19:26:14 2011
@@ -20,3 +20,15 @@
   o.foo; // expected-error{{property 'foo' not found on object of type 'id'}}
 }
 
+// rdar://8851803
+ at class SomeOtherClass; // expected-note {{forward class is declared here}}
+
+ at interface MyClass {
+    SomeOtherClass *someOtherObject;
+}
+ at end
+
+void foo(MyClass *myObject) {
+	myObject.someOtherObject.someProperty = 0; // expected-error {{property 'someOtherObject' names an object of forward class type in class object 'MyClass *'}}
+}
+





More information about the cfe-commits mailing list