Bug 21322 – Struct field destructor not called when exception is thrown in the main struct destructor

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2020-10-17T11:59:34Z
Last change time
2024-12-13T19:12:14Z
Assigned to
No Owner
Creator
Tomáš Chaloupka
Moved to GitHub: dmd#19808 →

Comments

Comment #0 by chalucha — 2020-10-17T11:59:34Z
How to reproduce: ```D import std; struct Foo { Bar bar; bool err; ~this() { // scope(failure) destroy(bar); // < this fixes the Bar destructor call enforce(!err, "Test err"); } } struct Bar { static int refs; ~this() { refs--; } } void main() { { Foo f; Bar.refs = 1; } assert(Bar.refs == 0); try () { Foo f; f.err = true; Bar.refs = 1; }(); catch (Exception ex) {} assert(Bar.refs == 0); } ``` So when the exception is thrown within Foo destructor, Bar's destructor isn't called anymore.
Comment #1 by robert.schadek — 2024-12-13T19:12:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19808 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB