]> granicus.if.org Git - clang/commitdiff
ObjectiveC. ObjectiveC's collection selector expression in
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 10 Oct 2013 21:58:04 +0000 (21:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 10 Oct 2013 21:58:04 +0000 (21:58 +0000)
the fereach loop must be a non-const lvalue expression as
it will be assigned to at the beginning of the loop.
// rdar://15123684

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmt.cpp
test/SemaObjC/arc.m

index 1e01da1991140bfb3e6f6b98a4decd68b098bdc5..88ced4c7edd84332a8345964182dae18a0a58d45 100644 (file)
@@ -6423,6 +6423,8 @@ def err_selector_element_not_lvalue : Error<
   "selector element is not a valid lvalue">;
 def err_selector_element_type : Error<
   "selector element type %0 is not a valid object">;
+def err_selector_element_const_type : Error<
+  "selector element of type %0 cannot be a constant l-value expression">;
 def err_collection_expr_type : Error<
   "the type %0 is not a pointer to a fast-enumerable object">;
 def warn_collection_expr_type : Warning<
index 10e808eae3175a0b96b29d0769267594aeb26c76..2977404445a7b810d87700a2e1de08b0ed5ad1cd 100644 (file)
@@ -1711,6 +1711,9 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
           << First->getSourceRange());
 
       FirstType = static_cast<Expr*>(First)->getType();
+      if (FirstType.isConstQualified())
+        Diag(ForLoc, diag::err_selector_element_const_type)
+          << FirstType << First->getSourceRange();
     }
     if (!FirstType->isDependentType() &&
         !FirstType->isObjCObjectPointerType() &&
index 063e857c3422c8b0b640f1d73ac59c93e11a847f..060af24fa0d92f8820721738d163afeb22d56406 100644 (file)
@@ -772,3 +772,13 @@ void test(NSArray *x) {
   __strong NSMutableArray *y1 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
   PSNS y2 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
 }
+
+// rdar://15123684
+@class NSString;
+
+void foo(NSArray *array) {
+  for (NSString *string in array) {
+    for (string in @[@"blah", @"more blah", string]) { // expected-error {{selector element of type 'NSString *const __strong' cannot be a constant l-value}}
+    }
+  }
+}