summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-10-10 21:58:04 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-10-10 21:58:04 +0000
commit8bcf182b9df69e829aa16179b7f77b02511151f4 (patch)
treec579ae5c487697a56fdbdea1e0775bbfd5595d96
parentf6fe6bfffeefdd569fd3c52b681a11a777c2a738 (diff)
downloadbcm5719-llvm-8bcf182b9df69e829aa16179b7f77b02511151f4.tar.gz
bcm5719-llvm-8bcf182b9df69e829aa16179b7f77b02511151f4.zip
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 llvm-svn: 192399
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaStmt.cpp3
-rw-r--r--clang/test/SemaObjC/arc.m10
3 files changed, 15 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1e01da19911..88ced4c7edd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/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/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 10e808eae31..2977404445a 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -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() &&
diff --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m
index 063e857c342..060af24fa0d 100644
--- a/clang/test/SemaObjC/arc.m
+++ b/clang/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}}
+ }
+ }
+}
OpenPOWER on IntegriCloud