-preview=safer for D

kdevel kdevel at vogtner.de
Sat Dec 14 10:46:45 UTC 2024


On Saturday, 14 December 2024 at 09:44:05 UTC, Daniel N wrote:
> On Saturday, 14 December 2024 at 08:46:35 UTC, Walter Bright 
> wrote:
>> Now that this has been merged into master, what are your 
>> reactions?
>
> Brilliant, I seldom used @safe, so this is just what I needed.

BTW: Is it intended that this code

    import std.stdio;

    @safe:

    void allocate (ref int [] a)
    {
       int [16] b;
       writeln (b);
       a = b;
    }

    void main ()
    {
       int [] c;
       allocate (c);
       writeln (c);
    }

not only requires the "@safe" but also the -dip1000 switch
in order to reject compilation:

    u.d(9): Error: address of variable `b` assigned to `a` with 
longer lifetime

Why does the compiler make it so difficult to enable this 
diagnostics?


More information about the Digitalmars-d mailing list