]> granicus.if.org Git - clang/commitdiff
Handle placeholder expressions in an ObjC for-collection loop.
authorJohn McCall <rjmccall@apple.com>
Fri, 30 Mar 2012 05:43:39 +0000 (05:43 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 30 Mar 2012 05:43:39 +0000 (05:43 +0000)
The way we handle this implicitly removes the ability to use
property l-values in this position, but that's really okay.

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

lib/Sema/SemaStmt.cpp
test/SemaObjC/foreach.m

index 39e8a1a1b92d66c680ced2972927ea6e9e8fae11..97c8eb04e9e1558ea46d23934eb557a64bb1e95f 100644 (file)
@@ -1079,10 +1079,18 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
 /// x can be an arbitrary l-value expression.  Bind it up as a
 /// full-expression.
 StmtResult Sema::ActOnForEachLValueExpr(Expr *E) {
+  // Reduce placeholder expressions here.  Note that this rejects the
+  // use of pseudo-object l-values in this position.
+  ExprResult result = CheckPlaceholderExpr(E);
+  if (result.isInvalid()) return StmtError();
+  E = result.take();
+
   CheckImplicitConversions(E);
-  ExprResult Result = MaybeCreateExprWithCleanups(E);
-  if (Result.isInvalid()) return StmtError();
-  return Owned(static_cast<Stmt*>(Result.get()));
+
+  result = MaybeCreateExprWithCleanups(E);
+  if (result.isInvalid()) return StmtError();
+
+  return Owned(static_cast<Stmt*>(result.take()));
 }
 
 ExprResult
index c865374e61affa9dab7729257f97617a69f523fc..d0e0f7b9e21421056d6ed6334ad6685755536696 100644 (file)
@@ -46,3 +46,12 @@ int main ()
  return 0;
 }
 
+/* rdar://problem/11068137 */
+@interface Test2
+@property (assign) id prop;
+@end
+void test2(NSObject<NSFastEnumeration> *collection) {
+  Test2 *obj;
+  for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */
+  }
+}