On 24.05.20 02:55, Arine wrote:
That works even if you make the static this() @safe, and remove the pointer incrementation.

Sure. `*p = 13;` is perfectly @safe. The static constructor isn't needed for that part. You can just as well do the assignment in `main`. The static constructor is another feature that can smuggle unsafe code (the increment) into your program without the @trusted warning label.

You'd have to make the p initialization @safe.

     @safe:
         int* p = cast(int*) &x; // error

But note this doesn't work:

     @safe int* p = cast(int*) &x; // compiles

Having the default become @safe will help detect this, as I don't imagine that is a whole lot of usage of @safe: to begin with.

The example compiles with `-preview=safedefault`. And even if that gets changed, it will probably still compile when marked @system. So we still won't find it when looking for "@trusted".

Reply via email to