On Sunday, 23 November 2014 at 19:37:45 UTC, Nordlöw wrote:
I just noticed that

void foo() @safe pure nothrow
{
    void[] void_array = new void[3];
    auto ubyte_array = cast(ubyte[])void_array;
    auto short_array = cast(short[])void_array;
}

compiles but gives a

object.Error@(0): array cast misalignment

because of the

    cast(short[])

I'm surprised---why is cast between different alignments and element lengths allowed at all in Safe D?

As far as I understand, it's @safe because it's guaranteed to
fail at run time on mismatches.

Similarly, array accesses are @safe because invalid ones will
throw RangeError:
void foo(int[] a) @safe {a[100] = 13;}

And even pointer dereferencing is @safe. Invalid ones will fail
with a segfault at run time:
void foo(int* a) @safe {*a = 13;}

Reply via email to