digitalmars.D.bugs - [Issue 9335] New: Dtors are not called for dynamic arrays initialized by literals
- d-bugmail puremagic.com Jan 17 2013
- d-bugmail puremagic.com Jan 17 2013
- d-bugmail puremagic.com Jan 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9335 Summary: Dtors are not called for dynamic arrays initialized by literals Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: maxim maxim-fomin.ru --- Comment #0 from Maxim Fomin <maxim maxim-fomin.ru> 2013-01-17 08:34:20 PST --- Dynamic arrays of structs initialized by array literals go out of scope without calling destructors. This does not happen with static arrays. import std.stdio : writefln; struct S { int i; this(this) { writefln("%X postbit", i); i = 0;} ~this() { writefln("%X dtor", i); } } void main() { S[] arr = [S()]; } Issue is maked as dmd issue, because druntime cannot call destructors when AA array goes out of the scope. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9335 monarchdodra gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra gmail.com See Also| |http://d.puremagic.com/issu | |es/show_bug.cgi?id=9334 --- Comment #1 from monarchdodra gmail.com 2013-01-17 08:39:31 PST --- (In reply to comment #0)Dynamic arrays of structs initialized by array literals go out of scope without calling destructors. This does not happen with static arrays. import std.stdio : writefln; struct S { int i; this(this) { writefln("%X postbit", i); i = 0;} ~this() { writefln("%X dtor", i); } } void main() { S[] arr = [S()]; } Issue is maked as dmd issue, because druntime cannot call destructors when AA array goes out of the scope.
Same answer as in http://d.puremagic.com/issues/show_bug.cgi?id=9334. The array is allocated dynamically, and makes no promises it will release at the end of the scope, or of the program. I'm not sure what you mean by "array literals", but you'll get the same behavior with: S[] arr = new S[](5); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9335 --- Comment #2 from Maxim Fomin <maxim maxim-fomin.ru> 2013-01-17 10:07:54 PST --- (In reply to comment #1)Same answer as in http://d.puremagic.com/issues/show_bug.cgi?id=9334. The array is allocated dynamically, and makes no promises it will release at the end of the scope, or of the program. I'm not sure what you mean by "array literals", but you'll get the same behavior with: S[] arr = new S[](5);
Well, situation here is different than in issue 9334 import core.stdc.stdio : printf; struct S { int i; this(this) { printf("%X postbit\n", i); i = 0;} ~this() { printf("%X dtor\n", i); } } void main() { S[] arr = [S()]; } Dump of assembler code for function _Dmain: 0x0000000000418894 <+0>: push %rbp 0x0000000000418895 <+1>: mov %rsp,%rbp 0x0000000000418898 <+4>: sub $0x10,%rsp 0x000000000041889c <+8>: movabs $0x1,%rsi 0x00000000004188a6 <+18>: movabs $0x6362a0,%rdi 0x00000000004188b0 <+28>: callq 0x41a610 <_d_arrayliteralTX> 0x00000000004188b5 <+33>: xor %ecx,%ecx 0x00000000004188b7 <+35>: mov %ecx,-0x8(%rbp) 0x00000000004188ba <+38>: lea -0x8(%rbp),%rsi 0x00000000004188be <+42>: mov %rax,%rdi 0x00000000004188c1 <+45>: movsb %ds:(%rsi),%es:(%rdi) 0x00000000004188c2 <+46>: movsb %ds:(%rsi),%es:(%rdi) 0x00000000004188c3 <+47>: movsb %ds:(%rsi),%es:(%rdi) 0x00000000004188c4 <+48>: movsb %ds:(%rsi),%es:(%rdi) 0x00000000004188c5 <+49>: mov %rax,%rdx 0x00000000004188c8 <+52>: movabs $0x1,%rax 0x00000000004188d2 <+62>: mov %rcx,%rax 0x00000000004188d5 <+65>: leaveq 0x00000000004188d6 <+66>: retq End of assembler dump. Array literal is allocated by _d_arrayliteralTX, yet is initialized by a stack temporary S(). Where a dtor call on it? The behavior is in contrast to issue 9334 when a dtor in similar situation is called. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 17 2013









d-bugmail puremagic.com 