Both safe and wrong?

ag0aep6g anonymous at example.com
Mon Feb 4 00:31:36 UTC 2019


On 04.02.19 01:18, ag0aep6g wrote:
> The thing here is that the @safe attribute only applies to functions. 
> `int* y = cast(int*) &x;` is not a function declaration, so `@safe:` has 
> no effect on it.
> 
> All code that's not in a function is @system, always. There is no way to 
> mark it as @safe.

Maybe even more peculiar than globals, you also can't mark parameter 
default values as @safe:

----
import std.stdio;

@safe:

immutable x = 42;

void main()
{
     *f() = 7;
     writeln(x); // 42
     writeln(*&x); // 7
}

int* f(int* y = cast(int*) &x) { return y; }
----


More information about the Digitalmars-d mailing list