[Issue 11329] New: Struct dtor called for a struct with a failed ctor when struct is nested in a class
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 23 07:10:54 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11329
Summary: Struct dtor called for a struct with a failed ctor
when struct is nested in a class
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-10-23 07:10:52 PDT ---
-----
module test;
import std.exception;
import std.stdio;
class C
{
this()
{
s = S(1);
}
S s;
}
struct S
{
this(int x)
{
_x = x;
int f;
if (!f) throw new Exception("");
}
~this()
{
stderr.writefln("S dtor -- _x: %s", _x);
}
int _x = -1;
}
void main()
{
// S dtor not called (ok, because its ctor failed)
assertThrown!Exception(S(1));
// S dtor called even though S object was not
// properly initialized (ctor failed)
assertThrown!Exception(new C());
}
-----
The S object is left in an improperly-initialized state since its ctor failed
(due to the thrown Exception), but for some reason its dtor /is/ called,
however only in a situation when it's nested in a class.
--
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