www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14028] New: [CTFE] Possible reinterpret cast to a pointer to


          Issue ID: 14028
           Summary: [CTFE] Possible reinterpret cast to a pointer to
                    static array
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE, rejects-valid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

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
test.d(9):        called from here: test()
test.d(9):        while evaluating: static assert(test())

Jan 22 2015