mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-03-04 19:33:13 +01:00
[svn r55] Foreach was always generating code as if the value variable was 'ref'
Other not-so-major improvements
This commit is contained in:
24
test/foreach5.d
Normal file
24
test/foreach5.d
Normal file
@@ -0,0 +1,24 @@
|
||||
module foreach5;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[3] arr = [1,2,3];
|
||||
|
||||
foreach(v;arr) {
|
||||
v++;
|
||||
}
|
||||
|
||||
printf("%d\n", arr[0]);
|
||||
assert(arr[0] == 1);
|
||||
assert(arr[1] == 2);
|
||||
assert(arr[2] == 3);
|
||||
|
||||
foreach(ref v;arr) {
|
||||
v++;
|
||||
}
|
||||
|
||||
printf("%d\n", arr[0]);
|
||||
assert(arr[0] == 2);
|
||||
assert(arr[1] == 3);
|
||||
assert(arr[2] == 4);
|
||||
}
|
||||
15
test/foreach6.d
Normal file
15
test/foreach6.d
Normal file
@@ -0,0 +1,15 @@
|
||||
module foreach6;
|
||||
|
||||
struct S
|
||||
{
|
||||
long l;
|
||||
float f;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
S[4] arr;
|
||||
foreach(i,v;arr) {
|
||||
v = S(i,i*2.5);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user