@safe - why does this compile?

ketmar ketmar at ketmar.no-ip.org
Fri Jul 13 11:22:44 UTC 2018


Piotr Mitana wrote:

> This code:
>
>      import std.stdio;
>
>      class X1 {}
>      class X2 : X1
>      {
> 	void run() @safe
>          {
>              writeln("DONE");
>          }
>      }
>
>      void main() @safe
>      {
>          X1 x1 = new X1;
>          X2 x2 = cast(X2) x1;
>          x2.run();
>      }
>
> is obviously wrong gets killed by OS's signal. Why is it @safe? I thought 
> @safe should prevent such errors as well.

there is nothing wrong here. dereferencing null reference is completely 
safe (in terms of result predictability).


More information about the Digitalmars-d-learn mailing list