Bug 7245 – [CTFE] Address of ref foreach parameter changes to point after array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2012-01-07T21:37:00Z
Last change time
2015-06-09T05:10:44Z
Keywords
ice-on-valid-code
Assigned to
nobody
Creator
verylonglogin.reg
Comments
Comment #0 by verylonglogin.reg — 2012-01-07T21:37:03Z
---
int func() {
int[2] arr;
int* ptr;
foreach(i, ref p; arr) if(i == 0)
ptr = &p;
int j = *ptr;
return 0;
}
enum e = func();
---
Error: array index 2 is out of bounds [0,0][0 .. 2]
Error: CTFE internal error: illegal value __error
Assertion failure: 'isCtfeValueValid(newval)' on line 6369 in file 'interpret.c'
Comment #1 by verylonglogin.reg — 2012-01-07T21:57:25Z
Another illustration (foreach is in function now):
---
int func() {
int[2] arr;
int* ptr;
void f() {
//Error: variable __aggr3 is used before initialization
foreach(i, ref p; arr) if(i == 0)
ptr = &p;
}
f();
int i = *ptr;
return 0;
}
enum e = func();
---