[cfe-commits] r125699 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/property-missing.m
Ted Kremenek
kremenek at apple.com
Wed Feb 16 17:59:25 PST 2011
Hi Fariborz,
I'm not certain this diagnostic is any better:
+ myObject.someOtherObject.someProperty = 0; // expected-error {{property 'someOtherObject' names an object of forward class type in class object 'MyClass *'}}
What is a "forward class type"? I know what you mean; you're talking about a Objective-C class that has only been forward declared, but there is no such thing as a forward class type.
How about:
property 'someOtherObject' refers to a Objective-C class ('SomeOtherClass') with only a forward declaration (no @interface available)
This diagnostic clearly spells out that (a) no @interface is available for (b) the class SomeOtherClass when (c) accessing the property someOtherObject.
On Feb 16, 2011, at 5:26 PM, Fariborz Jahanian wrote:
> 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 *'}}
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list