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())
Comment #1 by k.hara.pg — 2015-01-22T13:19:21Z
Comment #2 by github-bugzilla — 2015-01-23T13:33:27Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/473cef885b499c5620f6dfd93a0a56771d0dd3bc fix Issue 14028 - [CTFE] Possible reinterpret cast to a pointer to static array Use AddrExp + SliceExp (&aggr[a..b]) to represent a CTFE pointer to static array. https://github.com/D-Programming-Language/dmd/commit/4a8df52639d963f6278207e7aed694fc10861dc6 Merge pull request #4326 from 9rnsr/fix14028 Issue 14028 - [CTFE] Possible reinterpret cast to a pointer to static array