mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-26 00:23:14 +01:00
Fix nested references to 'ref' foreach variables.
These "walk around" the array being iterated over, so they're a bit trickier than other variables to get right.
This commit is contained in:
@@ -1 +1,8 @@
|
||||
void foo() { void delegate()[] bar; try {} finally { foreach (dg; bar) dg(); } }
|
||||
void foo() {
|
||||
void delegate()[] bar;
|
||||
try {
|
||||
} finally {
|
||||
foreach (dg; bar)
|
||||
dg();
|
||||
}
|
||||
}
|
||||
|
||||
19
tests/mini/foreach10.d
Normal file
19
tests/mini/foreach10.d
Normal file
@@ -0,0 +1,19 @@
|
||||
module foreach10;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main() {
|
||||
char* last = null;
|
||||
printf("The addresses should increment:\n");
|
||||
foreach (ref c; "bar") {
|
||||
auto a = {
|
||||
printf("%x '%c'\n", c, c);
|
||||
return &c;
|
||||
};
|
||||
auto nw = a();
|
||||
printf("ptr = %p\n", nw);
|
||||
if (last != null)
|
||||
assert(nw == last+1);
|
||||
last = nw;
|
||||
}
|
||||
}
|
||||
18
tests/mini/foreach11.d
Normal file
18
tests/mini/foreach11.d
Normal file
@@ -0,0 +1,18 @@
|
||||
module foreach11;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main() {
|
||||
char* last = null;
|
||||
printf("The addresses should remain constant:\n");
|
||||
foreach (c; "bar") {
|
||||
auto a = {
|
||||
printf("%x '%c'\n", c, c);
|
||||
printf("ptr = %p\n", &c);
|
||||
if (last)
|
||||
assert(last == &c);
|
||||
};
|
||||
a();
|
||||
last = &c;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user