October 17, 2020 [Issue 21322] New: Struct field destructor not called when exception is thrown in the main struct destructor | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21322 Issue ID: 21322 Summary: Struct field destructor not called when exception is thrown in the main struct destructor Product: D Version: D2 Hardware: x86_64 OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: chalucha@gmail.com 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. -- |
Copyright © 1999-2021 by the D Language Foundation