From: Fariborz Jahanian Date: Thu, 10 Oct 2013 21:58:04 +0000 (+0000) Subject: ObjectiveC. ObjectiveC's collection selector expression in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84e41cd7b0f0d1c8724c765ce53b842bc50367cc;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192399 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1e01da1991..88ced4c7ed 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 10e808eae3..2977404445 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1711,6 +1711,9 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, << First->getSourceRange()); FirstType = static_cast(First)->getType(); + if (FirstType.isConstQualified()) + Diag(ForLoc, diag::err_selector_element_const_type) + << FirstType << First->getSourceRange(); } if (!FirstType->isDependentType() && !FirstType->isObjCObjectPointerType() && diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index 063e857c34..060af24fa0 100644 --- a/test/SemaObjC/arc.m +++ b/test/SemaObjC/arc.m @@ -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}} + } + } +}