[cfe-commits] r155036 - in /cfe/trunk: lib/Sema/SemaPseudoObject.cpp test/SemaObjC/error-implicit-property.m
David Blaikie
dblaikie at gmail.com
Wed Apr 18 12:35:03 PDT 2012
On Wed, Apr 18, 2012 at 12:13 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Wed Apr 18 14:13:23 2012
> New Revision: 155036
>
> URL: http://llvm.org/viewvc/llvm-project?rev=155036&view=rev
> Log:
> objective-c: Issue diagnostic when an implicit
> property accessor (getter) missing, instead of crashing.
> // rdar://11273060
Nice - thanks!
> Added:
> cfe/trunk/test/SemaObjC/error-implicit-property.m
> Modified:
> cfe/trunk/lib/Sema/SemaPseudoObject.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=155036&r1=155035&r2=155036&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Wed Apr 18 14:13:23 2012
> @@ -214,6 +214,7 @@
>
> ObjCMethodDecl *Setter;
> Selector SetterSelector;
> + Selector GetterSelector;
>
> public:
> ObjCPropertyOpBuilder(Sema &S, ObjCPropertyRefExpr *refExpr) :
> @@ -475,8 +476,24 @@
>
> // For implicit properties, just trust the lookup we already did.
> if (RefExpr->isImplicitProperty()) {
> - Getter = RefExpr->getImplicitPropertyGetter();
> - return (Getter != 0);
> + if ((Getter = RefExpr->getImplicitPropertyGetter())) {
> + GetterSelector = Getter->getSelector();
> + return true;
> + }
> + else {
> + // Must build the getter selector the hard way.
> + ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter();
> + assert(setter && "both setter and getter are null - cannot happen");
> + IdentifierInfo *setterName =
> + setter->getSelector().getIdentifierInfoForSlot(0);
> + const char *compStr = setterName->getNameStart();
> + compStr += 3;
> + IdentifierInfo *getterName = &S.Context.Idents.get(compStr);
> + GetterSelector =
> + S.PP.getSelectorTable().getNullarySelector(getterName);
> + return false;
> +
> + }
> }
>
> ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
> @@ -776,7 +793,7 @@
> assert(RefExpr->isImplicitProperty());
> S.Diag(opcLoc, diag::err_nogetter_property_incdec)
> << unsigned(UnaryOperator::isDecrementOp(opcode))
> - << RefExpr->getImplicitPropertyGetter()->getSelector() // FIXME!
> + << GetterSelector
> << op->getSourceRange();
> return ExprError();
> }
>
> Added: cfe/trunk/test/SemaObjC/error-implicit-property.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/error-implicit-property.m?rev=155036&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/error-implicit-property.m (added)
> +++ cfe/trunk/test/SemaObjC/error-implicit-property.m Wed Apr 18 14:13:23 2012
> @@ -0,0 +1,30 @@
> +// RUN: %clang_cc1 -verify %s
> +// rdar://11273060
> +
> + at interface I
> +- (void) setP : (int)arg;
> + at end
> +
> + at interface J
> + - (int) P;
> + at end
> +
> + at interface K @end
> +
> + at interface II @end
> +
> + at implementation II
> +- (void) Meth : (I*) arg {
> + arg.P++; // expected-error {{no getter method 'P' for increment of property}}
> + --arg.P; // expected-error {{no getter method 'P' for decrement of property}}
Just out of curiosity - is there a reason that this particular line,
out of all six cases, uses the prefix form rather than the postfix?
> +}
> +- (void) Meth1 : (J*) arg {
> + arg.P++; // expected-error {{no setter method 'setP:' for increment of property}}
> + arg.P--; // expected-error {{no setter method 'setP:' for decrement of property}}
> +}
> +
> +- (void) Meth2 : (K*) arg {
> + arg.P++; // expected-error {{property 'P' not found on object of type 'K *'}}
> + arg.P--; // expected-error {{property 'P' not found on object of type 'K *'}}
> +}
> + at end
>
>
> _______________________________________________
> 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