Permalink
Browse files

Merge pull request #1276 from 9rnsr/fix6652a

Appendix for Issue 6652
  • Loading branch information...
2 parents 39a7788 + 780ce35 commit 882324ed350d087949e000a78b32c75396ea003a @WalterBright WalterBright committed Nov 13, 2012
Showing with 28 additions and 2 deletions.
  1. +2 −2 src/expression.c
  2. +13 −0 test/fail_compilation/fail6652a.d
  3. +13 −0 test/fail_compilation/fail6652b.d
View
@@ -5144,11 +5144,11 @@ Expression *VarExp::modifiableLvalue(Scope *sc, Expression *e)
#if (BUG6652 == 1)
VarDeclaration *v = var->isVarDeclaration();
- if (v && (v->storage_class & STCbug6652))
+ if (v && (v->storage_class & STCbug6652) && v->type->isMutable())
warning("variable modified in foreach body requires ref storage class");
#elif (BUG6652 == 2)
VarDeclaration *v = var->isVarDeclaration();
- if (v && (v->storage_class & STCbug6652))
+ if (v && (v->storage_class & STCbug6652) && v->type->isMutable())
deprecation("variable modified in foreach body requires ref storage class");
#endif
@@ -3,11 +3,24 @@
/******************************************/
// 6652
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail6652a.d(19): Warning: variable modified in foreach body requires ref storage class
+fail_compilation/fail6652a.d(24): Error: cannot modify const expression i
+---
+*/
+
void main()
{
size_t[] res;
foreach (i; 0..2)
{
res ~= ++i;
}
+
+ foreach (const i; 0..2)
+ {
+ ++i;
+ }
}
@@ -3,11 +3,24 @@
/******************************************/
// 6652
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail6652b.d(19): Warning: variable modified in foreach body requires ref storage class
+fail_compilation/fail6652b.d(24): Error: cannot modify const expression i
+---
+*/
+
void main()
{
size_t[] res;
foreach (i, e; [1,2,3,4,5])
{
res ~= ++i;
}
+
+ foreach (const i, e; [1,2,3,4,5])
+ {
+ ++i;
+ }
}

0 comments on commit 882324e

Please sign in to comment.