You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[REG 2.096] Double destruction of new'ed aggregates since -preview=dtorfields became the default #18037
```Dimport std;pragma(msg, __VERSION__);class Test { S s; this() { if (uniform(1, 10) != 0) throw new Exception("oops"); s = S(13); }}struct S { int x = 42; int y; this(int y) { this.y = y; }; this(this) { assert(x == 42); } ~this() { if (x != 42) writeln("OH NO!"); x = 0; // omitting this makes "OH NO!" go away }}void main(){ try new Test; catch (Exception e) writeln("Expected fail: ", e.msg);}```
Result:
```2096LExpected fail: oopsOH NO!```
This happens because the class ctor destructs it, then the GC, upon collecting the object, finalize the class again.
pro.mathias.lang (@Geod24) commented on 2021-06-02T11:54:25Z
Bug found in a large application using Vibe.d: https://github.com/vibe-d/vibe-core/issues/283
moonlightsentinel commented on 2021-06-02T12:40:42Z
Thats bad. I guess the destructed class instance should be GC.free'd if the ctor is aborted by an exception. Alternatively could also reset the instance to it's init value.
@MoonlightSentinel created dlang/dmd pull request #12641 "Fix 21989 - Reset destructed instance with preview=dtorfields" fixing this issue:
- Fix 21989 - Reset destructed instance with preview=dtorfields
Emplacing the initializer ensures that the GC won't run the destructor
on an invalid instance.
Preventing the destructor call from the GC doesn't seem to be feasible
due to the potentually lesser qualified GC interface (not `pure`, ...).
https://github.com/dlang/dmd/pull/12641
Activity
dlangBugzillaToGithub commentedon Jun 2, 2021
pro.mathias.lang (@Geod24) commented on 2021-06-02T11:54:25Z
Bug found in a large application using Vibe.d: https://github.com/vibe-d/vibe-core/issues/283dlangBugzillaToGithub commentedon Jun 2, 2021
moonlightsentinel commented on 2021-06-02T12:40:42Z
dlangBugzillaToGithub commentedon Jun 6, 2021
moonlightsentinel commented on 2021-06-06T11:30:07Z
dlangBugzillaToGithub commentedon Jun 6, 2021
dlang-bot commented on 2021-06-06T15:09:57Z
dlangBugzillaToGithub commentedon Nov 11, 2023
info commented on 2023-11-11T06:46:46Z