Use-after-scope bug in Phobos unittest, how to fix?
user456
user456 at 123.de
Mon May 15 20:01:31 UTC 2023
On Monday, 15 May 2023 at 18:55:09 UTC, Johan wrote:
> Hi all,
> I found a bug in Phobos typecons unittest:
> https://github.com/ldc-developers/phobos/blob/6c83b490f7d6c66bf430e5249dae608848d3ac2c/std/typecons.d#LL7088C1-L7108C46
> ```d
> pure @system unittest
> {
> foreach (MyRefCounted; AliasSeq!(SafeRefCounted,
> RefCounted))
> {
> MyRefCounted!int* p;
> {
> auto rc1 = MyRefCounted!int(5);
> p = &rc1; // assigns reference to variable in inner
> scope...
> assert(rc1 == 5);
> assert(rc1._refCounted._store._count == 1);
> auto rc2 = rc1;
> assert(rc1._refCounted._store._count == 2);
> // Reference semantics
> rc2 = 42;
> assert(rc1 == 42);
> rc2 = rc2;
> assert(rc2._refCounted._store._count == 2);
> rc1 = rc2;
> assert(rc1._refCounted._store._count == 2);
> }
> assert(p._refCounted._store == null); // use after
> scope!
> ```
>
> [...]
>
> Ideas?
>
> thanks,
> Johan
I'd simply suggest to remove the assertion or to put it in the
inner scope given that the problem is presumably that all allocas
for the unittest are done on function entry
More information about the Digitalmars-d
mailing list