-preview=in might break code

Walter Bright newshound2 at digitalmars.com
Mon Oct 5 07:52:54 UTC 2020


On 10/4/2020 7:19 AM, Iain Buclaw wrote:
> Plucking a fitting example from a Phobos unittest that demonstrates the kind of 
> things DMD let's people get away with:
> ```
> RefCounted!int* p;
> {
>      auto rc1 = RefCounted!int(5);
>      p = &rc1;
>      assert(rc1 == 5);
>      assert(rc1._refCounted._store._count == 1);
>      auto rc2 = rc1;
>      assert(rc1._refCounted._store._count == 2);
> }
> assert(p._refCounted._store == null);
> ```
> Why is this not a compile-time error?  DMD just isn't punishing users enough for 
> the buggy code they've written.

It's not allowed in @safe code.


More information about the Digitalmars-d mailing list