October 08, 2014 [Issue 13586] New: Destructors not run when argument list evaluation throws | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13586 Issue ID: 13586 Summary: Destructors not run when argument list evaluation throws Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: blocker Priority: P1 Component: DMD Assignee: nobody@puremagic.com Reporter: bugzilla@digitalmars.com The following test case illustrates it - only s should be constructed, and when throwit() throws, it should be destructed. It isn't. ------------------------------------------ import core.stdc.stdio; struct S { static int count; ~this() { ++count; } } int throwit() { throw new Exception("whatevah"); } void neverland(S s, int x, S t) { } void main() { try { neverland(S(), throwit(), S()); } catch (Exception e) { printf("%d\n", S.count); assert(S.count == 1); } } C:\cbx\mars>foo 0 core.exception.AssertError@foo.d(19): Assertion failure ----------------------------------------------- The fix is similar to what Kenji did to ensure left to right order of evaluation of arguments. If any arguments have destructors, then the argument list has to be constructed before attempting to put the argument list on the stack, because destructing them on a partially built stack is problematic. The arguments are then blitted to the stack, because the blit operation cannot throw. Note that this solution relies on D's requirement that a struct instance cannot have internal pointers to itself. This bug blocks a reliable ref counting implementation. -- |
Copyright © 1999-2021 by the D Language Foundation