Blog Post: What Does Memory Safety Really Mean in D?
Dennis
dkorpel at gmail.com
Wed Aug 26 15:34:26 UTC 2020
On Wednesday, 26 August 2020 at 14:29:46 UTC, Dukc wrote:
> I think there is a workaround to the variable access being
> always safe. Something like this in a dedicated module:
>
> ```
> struct SystemVar(T, bool safeVal)
> { private T _var;
> static if (safeVal) @safe pure nothrow @nogc auto val()
> { return _var;
> }
> else pure nothrow @nogc auto val(){return _var;}
> pure nothrow @nogc ref var(){return _var;}
> }
> ```
This currently does not protect against:
- SystemVar.tupleof[0] (unless you have -preview=dip1000 set)
- __traits(getMember, SystemVar, "_var")
- aliasing (put SystemVar!int in a union with a plain int / cast
SystemVar!int[] from int[])
- void initialization
More information about the Digitalmars-d-announce
mailing list