struct dtor never called, what's wrong?
Andrea Fontana
nospam at example.com
Fri Jun 15 14:29:32 UTC 2018
Maybe it's just a big blunder, but I think there's something
wrong in phobos.
All started a couple of days ago, when I was investigating on
some not-freed resource on my code.
It turns out that on "each" function inside phobos it is used a
"ref foreach". Something like:
foreach(ref element, myRange) {}
If myRange.front() doesn't return a ref, this syntax probably
should be rejected, but it is accepted. So for each iterated
element a ctor is called but not a dtor.
Discussing this with Rikki we discovered a similar bug is still
opened [1] but was not related with missing dtor call, actually.
If "each" maybe is not so used, a similar problem popped out in
another part of my code, using std.array : array. Apparently
there is no "for-each-ref" code there.
That's fun because I was actually working on a workaround for
another bug [2] I've found in the same code base.
Anyway code [3] (assumePure is a workaround for [2]) shows that 4
dtor call are missing (element constructed by array).
I wonder how diffused is this bug considering that "array" is a
pretty used function. This leads to a leak on my code.
I hope I'm wrong. Maybe I'm missing something. Anyone can help?
Andrea
[1] https://issues.dlang.org/show_bug.cgi?id=11934
[2]
https://forum.dlang.org/post/kfaakznkdnnoxwcrgtsg@forum.dlang.org
[3] https://run.dlang.io/is/IMqYzK
More information about the Digitalmars-d
mailing list