Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 12, 2013 [Issue 9704] Destructor not called on function calls if postblit throws | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9704 Johannes Pfau <johannespfau@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |d.gnu@puremagic.com, | |johannespfau@gmail.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the issue. |
March 12, 2013 [Issue 9704] Destructor not called on function calls if postblit throws | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9704 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim@maxim-fomin.ru --- Comment #2 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-03-12 13:13:41 PDT --- (In reply to comment #0) > The problem is that the destructors are currently called in the callee but the postblits in the caller. If an exception is thrown in between those calls, the destructor can't be called. To be more precise, it happens during evaluation of function argument which follows some struct argument and throws exception. extern(C) int printf(const char* fmt, ...); struct A { this(this) { printf("A:this(this)\n");} ~this() { printf("A:~this\n"); } uint data; } int foo() { throw new Exception(""); } void func(A a, int i) {} void main() { A a; func(a, foo()); } Here should be two destructors: for "a" and " __cpcttmpXXX" structs. And calling dtor is unavoidable since postblit may deep copy some memory. > A possible solution is to move the destructor to the caller. But in this case the parameter (the copy) must be passed by invisible reference so that the destructor actually sees the updated value after the callee returns. > > (Note that it might be useful to make an exception for non-PODs without destructors here. Those shouldn't be affected by this issue and could be treated like PODs when being passed to a function as an optimization.) Alternatively a copy operation can be moved into callee or D runtime can be boosted to cope with such problem. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the issue. |
July 12, 2013 [Issue 9704] Destructor not called on function calls if postblit throws | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9704 monarchdodra@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@erdani.com --- Comment #3 from monarchdodra@gmail.com 2013-07-12 11:05:06 PDT --- *** Issue 10623 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the issue. |
July 12, 2013 [Issue 9704] Destructor not called on function calls if postblit throws | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9704 monarchdodra@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra@gmail.com --- Comment #4 from monarchdodra@gmail.com 2013-07-12 11:07:53 PDT --- (In reply to comment #3) > *** Issue 10623 has been marked as a duplicate of this issue. *** For reference, this was also discussed in learn. http://forum.dlang.org/group/digitalmars.D.learn http://forum.dlang.org/thread/20130628005448.00000969@unknown -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the issue. |
July 12, 2013 [Issue 9704] Destructor not called on function calls if postblit throws | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9704 --- Comment #5 from Andrei Alexandrescu <andrei@erdani.com> 2013-07-12 14:17:12 PDT --- Pasting the additional example here for reference: import std.stdio; struct S1 { this(int) { writeln("constructed"); } ~this() { writeln("destroyed"); } } struct S2 { this(int) { throw new Exception("a"); } } void fun(S1, S2, S1) {} void main() { fun(S1(2), S2(2), S1(2)); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the issue. |
Copyright © 1999-2021 by the D Language Foundation