[cfe-commits] r67491 - in /cfe/trunk: lib/AST/Expr.cpp test/Sema/block-literal.c

Eli Friedman eli.friedman at gmail.com
Sun Mar 22 16:26:56 PDT 2009


Author: efriedma
Date: Sun Mar 22 18:26:56 2009
New Revision: 67491

URL: http://llvm.org/viewvc/llvm-project?rev=67491&view=rev
Log:
Adjust isModifiableLvalue to give a slightly more useful diagnostic for 
attempting to illegally modify a BlockDeclRefExpr.


Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/Sema/block-literal.c

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=67491&r1=67490&r2=67491&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Mar 22 18:26:56 2009
@@ -781,7 +781,17 @@
     return MLV_InvalidExpression;
   case LV_MemberFunction: return MLV_MemberFunction;
   }
-  
+
+  // The following is illegal:
+  //   void takeclosure(void (^C)(void));
+  //   void func() { int x = 1; takeclosure(^{ x = 7; }); }
+  //
+  if (getStmtClass() == BlockDeclRefExprClass) {
+    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
+    if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
+      return MLV_NotBlockQualified;
+  }
+
   QualType CT = Ctx.getCanonicalType(getType());
   
   if (CT.isConstQualified())
@@ -795,15 +805,6 @@
     if (r->hasConstFields()) 
       return MLV_ConstQualified;
   }
-  // The following is illegal:
-  //   void takeclosure(void (^C)(void));
-  //   void func() { int x = 1; takeclosure(^{ x = 7 }); }
-  //
-  if (getStmtClass() == BlockDeclRefExprClass) {
-    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
-    if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
-      return MLV_NotBlockQualified;
-  }
   
   // Assigning to an 'implicit' property?
   else if (getStmtClass() == ObjCKVCRefExprClass) {

Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=67491&r1=67490&r2=67491&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Sun Mar 22 18:26:56 2009
@@ -39,7 +39,7 @@
 	}
 
 foo:
-	takeclosure(^{ x = 4; });  // expected-error {{read-only variable is not assignable}}
+	takeclosure(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
   __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
   takeclosure(^{ y = 8; });
 }





More information about the cfe-commits mailing list