[cfe-commits] r95838 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/property-not-lvalue.m

Daniel Dunbar daniel at zuster.org
Thu Feb 11 08:22:36 PST 2010


Hi Fariborz,

This doesn't feel right to me. Why is this different than:
--
struct s0 { int x; };
struct s0 f0();
void f1() { f0().x = 1; }
--

 - Daniel

On Wed, Feb 10, 2010 at 5:11 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Wed Feb 10 19:11:34 2010
> New Revision: 95838
>
> URL: http://llvm.org/viewvc/llvm-project?rev=95838&view=rev
> Log:
> Diagnose when user provided getter is being used as lvalue
> using property dot-syntax. Fixes radar 7628953.
>
>
> Modified:
>    cfe/trunk/include/clang/AST/Expr.h
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/AST/Expr.cpp
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/test/SemaObjC/property-not-lvalue.m
>
> Modified: cfe/trunk/include/clang/AST/Expr.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=95838&r1=95837&r2=95838&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Expr.h (original)
> +++ cfe/trunk/include/clang/AST/Expr.h Wed Feb 10 19:11:34 2010
> @@ -149,7 +149,8 @@
>     LV_DuplicateVectorComponents,
>     LV_InvalidExpression,
>     LV_MemberFunction,
> -    LV_SubObjCPropertySetting
> +    LV_SubObjCPropertySetting,
> +    LV_SubObjCPropertyGetterSetting
>   };
>   isLvalueResult isLvalue(ASTContext &Ctx) const;
>
> @@ -179,7 +180,8 @@
>     MLV_ReadonlyProperty,
>     MLV_NoSetterProperty,
>     MLV_MemberFunction,
> -    MLV_SubObjCPropertySetting
> +    MLV_SubObjCPropertySetting,
> +    MLV_SubObjCPropertyGetterSetting
>   };
>   isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
>                                               SourceLocation *Loc = 0) const;
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=95838&r1=95837&r2=95838&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 10 19:11:34 2010
> @@ -1869,7 +1869,11 @@
>  def error_nosetter_property_assignment : Error<
>   "setter method is needed to assign to object using property" " assignment syntax">;
>  def error_no_subobject_property_setting : Error<
> -  "cannot assign to a sub-structure of an ivar using property" " assignment syntax">;
> +  "cannot assign to a sub-structure of an ivar using property"
> +  " assignment syntax">;
> +def error_no_subobject_property_getter_setting : Error<
> +  "cannot assign to a sub-structure returned via a getter using property"
> +  " assignment syntax">;
>
>  def ext_freestanding_complex : Extension<
>   "complex numbers are an extension in a freestanding C99 implementation">;
>
> Modified: cfe/trunk/lib/AST/Expr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=95838&r1=95837&r2=95838&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/Expr.cpp (original)
> +++ cfe/trunk/lib/AST/Expr.cpp Wed Feb 10 19:11:34 2010
> @@ -1068,8 +1068,11 @@
>         if (m->isArrow())
>           return LV_Valid;
>         Expr *BaseExp = m->getBase();
> -        return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
> -                 LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
> +        if (BaseExp->getStmtClass() == ObjCPropertyRefExprClass)
> +          return LV_SubObjCPropertySetting;
> +        return
> +          (BaseExp->getStmtClass() == ObjCImplicitSetterGetterRefExprClass) ?
> +           LV_SubObjCPropertyGetterSetting : BaseExp->isLvalue(Ctx);
>       }
>
>       //   -- If it refers to a static member function [...], then
> @@ -1092,8 +1095,11 @@
>     if (m->isArrow())
>       return LV_Valid;
>     Expr *BaseExp = m->getBase();
> -    return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
> -             LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
> +    if (BaseExp->getStmtClass() == ObjCPropertyRefExprClass)
> +          return LV_SubObjCPropertySetting;
> +    return
> +      (BaseExp->getStmtClass() == ObjCImplicitSetterGetterRefExprClass) ?
> +       LV_SubObjCPropertyGetterSetting : BaseExp->isLvalue(Ctx);
>   }
>   case UnaryOperatorClass:
>     if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
> @@ -1283,7 +1289,9 @@
>     }
>     return MLV_InvalidExpression;
>   case LV_MemberFunction: return MLV_MemberFunction;
> -    case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
> +  case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
> +  case LV_SubObjCPropertyGetterSetting:
> +    return MLV_SubObjCPropertyGetterSetting;
>   }
>
>   // The following is illegal:
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=95838&r1=95837&r2=95838&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Feb 10 19:11:34 2010
> @@ -5734,6 +5734,9 @@
>   case Expr::MLV_SubObjCPropertySetting:
>     Diag = diag::error_no_subobject_property_setting;
>     break;
> +  case Expr::MLV_SubObjCPropertyGetterSetting:
> +    Diag = diag::error_no_subobject_property_getter_setting;
> +    break;
>   }
>
>   SourceRange Assign;
>
> Modified: cfe/trunk/test/SemaObjC/property-not-lvalue.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-not-lvalue.m?rev=95838&r1=95837&r2=95838&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/property-not-lvalue.m (original)
> +++ cfe/trunk/test/SemaObjC/property-not-lvalue.m Wed Feb 10 19:11:34 2010
> @@ -18,3 +18,17 @@
>         f.size.width = 2.2; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}}
>        f.size.inner.dim = 200; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}}
>  }
> +
> +// radar 7628953
> +
> + at interface Gorf  {
> +}
> +- (NSSize)size;
> + at end
> +
> + at implementation Gorf
> +- (void)MyView_sharedInit {
> +    self.size.width = 2.2; // expected-error {{cannot assign to a sub-structure returned via a getter using property assignment syntax}}
> +}
> +- (NSSize)size {}
> + 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