r192399 - ObjectiveC. ObjectiveC's collection selector expression in

Fariborz Jahanian fjahanian at apple.com
Thu Oct 10 14:58:04 PDT 2013


Author: fjahanian
Date: Thu Oct 10 16:58:04 2013
New Revision: 192399

URL: http://llvm.org/viewvc/llvm-project?rev=192399&view=rev
Log:
ObjectiveC. ObjectiveC's collection selector expression in
the fereach loop must be a non-const lvalue expression as
it will be assigned to at the beginning of the loop.
// rdar://15123684

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaObjC/arc.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=192399&r1=192398&r2=192399&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 10 16:58:04 2013
@@ -6423,6 +6423,8 @@ def err_selector_element_not_lvalue : Er
   "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<

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=192399&r1=192398&r2=192399&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Oct 10 16:58:04 2013
@@ -1711,6 +1711,9 @@ Sema::ActOnObjCForCollectionStmt(SourceL
           << 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() &&

Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=192399&r1=192398&r2=192399&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Thu Oct 10 16:58:04 2013
@@ -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
+ at 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}}
+    }
+  }
+}





More information about the cfe-commits mailing list