Bug 6792 – [CTFE] ICE with pointer cast of indexed array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-10-08T10:24:00Z
Last change time
2011-11-02T13:06:59Z
Assigned to
nobody
Creator
youxkei
Comments
Comment #0 by youxkei — 2011-10-08T10:24:56Z
struct S{
int i;
}
static assert({
{
void* p;
p = [S(1)].ptr;
S s = *(cast(S*)p);// OK
assert(s.i == 1);
}
{
void*[] ary;
ary ~= [S(2)].ptr;
S s = *(cast(S*)ary[0]);// Error: CTFE internal error assigning struct
assert(s.i == 2);
}
{
void*[string] aa;
aa["key"] = [S(3)].ptr;
S s = *(cast(S*)aa["key"]);// Error: CTFE internal error assigning struct
assert(s.i == 3);
}
return true;
}());
The latest dmd built from github cannot compile the above code.
Comment #1 by clugdbug — 2011-10-10T01:15:26Z
Another case, where it's an lvalue instead of an rvalue:
{
void*[7] ary;
ary[6]= [S(2)].ptr;
*(cast(S*)ary[6]) = S(4); //ICE(interpret.c 2965)
}
The root cause is that type painting of pointers hasn't been considered properly in CTFE.