]> granicus.if.org Git - clang/commitdiff
Using the property dot-syntax to invoke a non-eixsting
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 14 Sep 2009 16:40:48 +0000 (16:40 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 14 Sep 2009 16:40:48 +0000 (16:40 +0000)
structure-valued setter should cause a user error instead of
crash.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81769 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaObjC/property-error-readonly-assign.m

index fa020de7a37848e9de499311a1c9c90ad9e659cb..620b5b8901619b859c9f4e4335ca6d38ef1e17c4 100644 (file)
@@ -1061,12 +1061,18 @@ Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const {
   //   void takeclosure(void (^C)(void));
   //   void func() { int x = 1; takeclosure(^{ x = 7; }); }
   //
-  if (isa<BlockDeclRefExpr>(this)) {
-    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
+  if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) {
     if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
       return MLV_NotBlockQualified;
   }
-
+  
+  // Assigning to an 'implicit' property?
+  if (const ObjCImplicitSetterGetterRefExpr* Expr = 
+        dyn_cast<ObjCImplicitSetterGetterRefExpr>(this)) {
+    if (Expr->getSetterMethod() == 0)
+      return MLV_NoSetterProperty;
+  }
+  
   QualType CT = Ctx.getCanonicalType(getType());
 
   if (CT.isConstQualified())
@@ -1081,13 +1087,6 @@ Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const {
       return MLV_ConstQualified;
   }
 
-  // Assigning to an 'implicit' property?
-  else if (isa<ObjCImplicitSetterGetterRefExpr>(this)) {
-    const ObjCImplicitSetterGetterRefExpr* Expr =
-      cast<ObjCImplicitSetterGetterRefExpr>(this);
-    if (Expr->getSetterMethod() == 0)
-      return MLV_NoSetterProperty;
-  }
   return MLV_Valid;
 }
 
index edeff09dfadd77df5d8dcaab1da70e5928e0090f..d5cef78f18f4af7ed99bd6e4dc18d7b741a07ca1 100644 (file)
@@ -19,3 +19,26 @@ void f0(A *a, B* b) {
   b.ok = 20;
 }
 
+typedef struct {
+  int i1, i2;
+} NSRect;
+
+NSRect NSMakeRect();
+
+@interface NSWindow 
+{
+    NSRect _frame;
+}
+- (NSRect)frame;
+@end
+
+@interface NSWindow (Category)
+-(void)methodToMakeClangCrash;
+@end
+
+@implementation NSWindow (Category)
+-(void)methodToMakeClangCrash
+{
+ self.frame =  NSMakeRect(); // expected-error {{setter method is needed to assign to object using property assignment syntax}}
+}
+@end