Bug 14028 – [CTFE] Possible reinterpret cast to a pointer to static array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-22T11:06:00Z
Last change time
2015-01-23T13:33:28Z
Keywords
CTFE, pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-01-22T11:06:22Z
Following code should work, but doesn't.
int test()
{
int[4] mem;
int[2]* psa;
psa = cast(int[2]*)&mem[1];
(*psa)[0] = 1;
(*psa)[1] = 2;
assert(mem == [0, 1, 2, 0]);
return 1;
}
static assert(test());
Current compiler error:
test.d(6): Error: reinterpreting cast from int[4] to int[2]* is not supported in CTFE
test.d(9): called from here: test()
test.d(9): while evaluating: static assert(test())