Memory safe in D

bachmeier no at spam.net
Mon Mar 11 15:31:02 UTC 2024


On Monday, 11 March 2024 at 08:48:47 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> On 11/03/2024 9:16 PM, Alex wrote:
>> So I don't see any errors or warnings from compiler when I use 
>> uninitialized variable |a| and don't see any exception with 
>> backtrace in runtime (application is build in debug mode).
>> 
>> Is it expected behavior? Looks like it is not very safe 
>> approach and can lead to very unpleasant memory errors...
>
> This is expected behavior.
>
> The variable a was default initialized to null.
>
> D has not got type state analysis as part of it, so it cannot 
> detect this situation and cause an error.
>
> It is at the top of my todo list for memory safety research for 
> D, as the IR it requires enables other analysis and provides a 
> framework for it to exist in.

Rather than doing that, couldn't the compiler say `A a;` is not 
valid inside `@safe`?


More information about the Digitalmars-d mailing list