Bug 2341 – Double destruction without intervening copy

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-09-07T00:02:00Z
Last change time
2015-06-09T05:15:01Z
Assigned to
bugzilla
Creator
andrei

Comments

Comment #0 by andrei — 2008-09-07T00:02:23Z
import std.stdio; struct A { int id; this(int x) { id = x; writeln("Created object from scratch: ", x); } this(this) { writeln("Copying object: ", id); } ~this() { writeln("Destroying object: ", id); } } struct B { A member; } B foo() { A a = A(45); return B(a); } void main() { auto b = foo; } The code above prints: Created object from scratch: 45 Destroying object: 45 Destroying object: 45 Obviously there should be an intervening copy, otherwise the same state gets destructed twice. The correct output should be: Created object from scratch: 45 Destroying object: 45 Copying object: 45 Destroying object: 45
Comment #1 by bruno.do.medeiros+deebugz — 2008-09-08T09:03:37Z
Shouldn't the correct output be: Created object from scratch: 45 Copying object: 45 Destroying object: 45 Destroying object: 45 ? After all, the postblit in the "B(a)" expression must run before foo's scope ends and "a" is destroyed, right?
Comment #2 by andrei — 2008-09-08T09:45:51Z
(In reply to comment #1) > Shouldn't the correct output be: > > Created object from scratch: 45 > Copying object: 45 > Destroying object: 45 > Destroying object: 45 > > ? > After all, the postblit in the "B(a)" expression must run before foo's scope > ends and "a" is destroyed, right? > Correct, thank you.
Comment #3 by bugzilla — 2008-10-20T22:23:07Z
Fixed dmd 2.020