Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1009 from 9rnsr/fix6652_2

fix Issue 6652 - 2. Deprecate modifying non ref variable.
  • Loading branch information...
commit ae95b0f935e00ec03224180a24c4396485367eb8 2 parents 9f780b0 + ac7fd08
@MartinNowak MartinNowak authored
View
2  src/mars.h
@@ -90,7 +90,7 @@ void unittests();
#define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN
#define SARRAYVALUE DMDV2 // static arrays are value types
#define MODULEINFO_IS_STRUCT DMDV2 // if ModuleInfo is a struct rather than a class
-#define BUG6652 1 // Making foreach range statement parameter non-ref in default
+#define BUG6652 2 // Making foreach range statement parameter non-ref in default
// 1: Modifying iteratee in body is warned with -w switch
// 2: Modifying iteratee in body is error without -d switch
View
2  test/compilable/interpret3.d
@@ -4249,7 +4249,7 @@ static assert(bug7245(1)==5);
int bug8498()
{
- foreach(i; 0..5)
+ foreach(ref i; 0..5)
{
assert(i == 0);
i = 100;
View
6 test/fail_compilation/fail6652a.d
@@ -1,12 +1,12 @@
-// REQUIRED_ARGS: -w
-
+// REQUIRED_ARGS: -de
+// PERMUTE_ARGS: -w
/******************************************/
// 6652
/*
TEST_OUTPUT:
---
-fail_compilation/fail6652a.d(19): Warning: variable modified in foreach body requires ref storage class
+fail_compilation/fail6652a.d(19): Deprecation: variable modified in foreach body requires ref storage class
fail_compilation/fail6652a.d(24): Error: cannot modify const expression i
---
*/
View
6 test/fail_compilation/fail6652b.d
@@ -1,12 +1,12 @@
-// REQUIRED_ARGS: -w
-
+// REQUIRED_ARGS: -de
+// PERMUTE_ARGS: -w
/******************************************/
// 6652
/*
TEST_OUTPUT:
---
-fail_compilation/fail6652b.d(19): Warning: variable modified in foreach body requires ref storage class
+fail_compilation/fail6652b.d(19): Deprecation: variable modified in foreach body requires ref storage class
fail_compilation/fail6652b.d(24): Error: cannot modify const expression i
---
*/
View
21 test/runnable/deprecate1.d
@@ -1253,6 +1253,26 @@ void test18()
}
/******************************************/
+// 6652
+
+void test6652()
+{
+ size_t[] res1;
+ foreach (i; 0..2)
+ {
+ res1 ~= ++i;
+ }
+ assert(res1 == [1]);
+
+ size_t[] res2;
+ foreach (i, e; [0,1])
+ {
+ res2 ~= ++i;
+ }
+ assert(res2 == [1]);
+}
+
+/******************************************/
int main()
{
@@ -1312,6 +1332,7 @@ int main()
test6289();
test4237();
test18();
+ test6652();
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.