Test case: --------------------- static assert({ int[] arr = [1]; arr.ptr[0] = 2; // <-- line 3 return arr[0]; }() == 2); --------------------- y.d(3): Error: cannot determine length of cast(int*)arr at compile time y.d(5): Error: cannot evaluate delegate pure nothrow int() { int[] arr = [1]; (cast(int*)arr)[0u] = 2; return arr[0u]; } () at compile time y.d(1): Error: static assert (delegate pure nothrow int() { int[] arr = [1]; (cast(int*)arr)[0u] = 2; return arr[0u]; } () == 2) is not evaluatable at compile time --------------------- Slicing is OK, though.
Note that this prevents std.array.appender from being CTFE-able, because it contains the code: _data.arr.ptr[len] = cast(Unqual!T)item; // <-- error _data.arr = _data.arr.ptr[0 .. len + 1]; // (OK) Currently, this could be worked-around by swapping the two statements and use the standard indexing: _data.arr = _data.arr.ptr[0 .. len+1]; // OK _data.arr[len] = cast(Unqual!T)item; // now OK but I think the more proper solution is to fix this bug.
https://github.com/D-Programming-Language/dmd/commit/0904c8aa200e4d080d500d96d5904c33ba17cc86 https://github.com/D-Programming-Language/dmd/commit/e48a8c67f02172c72e04f36759d2d6868d716368