From: Fariborz Jahanian Date: Thu, 16 Dec 2010 00:56:28 +0000 (+0000) Subject: Improve diagnostics when property being looked up X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b1aba495744bea7093899a65f08c3987263061c;p=clang Improve diagnostics when property being looked up in a forward @class object. // rdar://8774513 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121933 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e9617a2f11..8095b94656 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2416,6 +2416,10 @@ def err_ref_array_type : Error< "cannot refer to declaration with an array type inside block">; def err_property_not_found : Error< "property %0 not found on object of type %1">; +def err_property_not_found_forward_class : Error< + "property %0 cannot be found in forward class object %1">; +def note_forward_class : Note< + "forward class is declared here">; def err_duplicate_property : Error< "property has a previous declaration">; def ext_gnu_void_ptr : Extension< diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 5d5e8a528b..baa34f9ce8 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -353,6 +353,12 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, ObjCInterfaceDecl *IFace = IFaceT->getDecl(); IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); + if (IFace->isForwardDecl()) { + Diag(MemberLoc, diag::err_property_not_found_forward_class) + << MemberName << QualType(OPT, 0); + Diag(IFace->getLocation(), diag::note_forward_class); + return ExprError(); + } // Search for a declared property first. if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Member)) { // Check whether we can reference this property. diff --git a/test/SemaObjC/property-9.m b/test/SemaObjC/property-9.m index 669f9c0e4b..2b6564d295 100644 --- a/test/SemaObjC/property-9.m +++ b/test/SemaObjC/property-9.m @@ -96,3 +96,14 @@ typedef signed char BOOL; - (float)setMyStyle:(int)style; @end +// rdar://8774513 +@class MDAInstance; // expected-note {{forward class is declared here}} + +@interface MDATestDocument +@property(retain) MDAInstance *instance; +@end + +id f0(MDATestDocument *d) { + return d.instance.path; // expected-error {{property 'path' cannot be found in forward class object 'MDAInstance *'}} +} +