Thread overview
[Issue 21989] [REG 2.096] Double destruction of classes since `-preview=dtorfields` became the default
[Issue 21989] [REF 2.096] Double destruction of classes since `-preview=dtorfields` became the default
Jun 02, 2021
Mathias LANG
Jun 06, 2021
Mathias LANG
[Issue 21989] [REG 2.096] Double destruction of new'ed aggregates since `-preview=dtorfields` became the default
Jun 06, 2021
Dlang Bot
June 02, 2021
https://issues.dlang.org/show_bug.cgi?id=21989

--- Comment #1 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Bug found in a large application using Vibe.d: https://github.com/vibe-d/vibe-core/issues/283

--
June 02, 2021
https://issues.dlang.org/show_bug.cgi?id=21989

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg

--- Comment #2 from moonlightsentinel@disroot.org ---
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.

--
June 06, 2021
https://issues.dlang.org/show_bug.cgi?id=21989

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[REF 2.096] Double          |[REG 2.096] Double
                   |destruction of classes      |destruction of classes
                   |since `-preview=dtorfields` |since `-preview=dtorfields`
                   |became the default          |became the default

--
June 06, 2021
https://issues.dlang.org/show_bug.cgi?id=21989

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[REG 2.096] Double          |[REG 2.096] Double
                   |destruction of classes      |destruction of new'ed
                   |since `-preview=dtorfields` |aggregates since
                   |became the default          |`-preview=dtorfields`
                   |                            |became the default

--- Comment #3 from moonlightsentinel@disroot.org ---
Not restricted to classes, also affects GC-allocated structs

--
June 06, 2021
https://issues.dlang.org/show_bug.cgi?id=21989

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
November 11
https://issues.dlang.org/show_bug.cgi?id=21989

Mai Lapyst <info@lapyst.by> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |info@lapyst.by

--- Comment #5 from Mai Lapyst <info@lapyst.by> ---
It seems that in 2.103.0 this bug was fixed; atleast the provided example doesn't produces the "OH NO!" anymore:

```
2103L
Expected fail: oops
```

--