[Issue 10972] New: aggregate postblit doesn't clean up in case of failure
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 5 07:26:22 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10972
Summary: aggregate postblit doesn't clean up in case of failure
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: monarchdodra at gmail.com
--- Comment #0 from monarchdodra at gmail.com 2013-09-05 07:26:20 PDT ---
Structs will not recursively destroy their members if the construction scheme
fails:
//####
import std.stdio;
struct A
{
this(this)
{writeln("copied A");}
~this()
{writeln("destroy A");}
}
struct B
{
this(this)
{
writeln("B says what?");
throw new Exception("BOOM!");
}
~this()
{writeln("destroy B");}
}
struct S
{
A a;
B b;
}
void main()
{
S s1;
S s2;
writeln("----");
try
s2 = s1;
catch
{}
writeln("----");
try
S s3 = s1;
catch
{}
writeln("----");
}
//####
----
copied A
B says what?
----
copied A
B says what?
----
destroy B
destroy A
destroy B
destroy A
//####
Be it CC, or "postblit-based" assignment, first, the "A" element is
constructed, the B fails to CC, but the first A is never actually destroyed.
Postblit should first destroy all created members before propagating the
exception.
This should be pretty standard and expected behavior for struct construction.
The irony is that only static arrays handle this correctly, but only because
they have their own (arguably weird) construction scheme.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list