[Issue 4712] New: Issue of destructor for temporary instance of structs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 22 06:29:10 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4712
Summary: Issue of destructor for temporary instance of structs
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: zan77137 at nifty.com
--- Comment #0 from SHOO <zan77137 at nifty.com> 2010-08-22 06:29:06 PDT ---
This code doesn't work!
import std.stdio;
auto func(int A = int.init)()
{
struct XXX
{
int a;
~this(){ writeln("dtor"); }
}
return XXX();
}
void main()
{
writeln("start");
{
auto x = func!();
}
writeln("end");
}
result:
start
dtor
end
object.Error: Access Violation
If I remove the destructor, it runs correctly.
Or I set -O switch to compiler, it runs correctly, too.
Workaround for this bug is making dummy constructor:
import std.stdio;
auto func(int A = int.init)()
{
struct XXX
{
int a;
this(int aa){ a = aa; writeln("ctor"); }
~this(){ writeln("dtor"); }
}
return XXX(A);
}
void main()
{
writeln("start");
{
auto x = func!();
}
writeln("end");
}
--
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