March 23, 2013 bug or not? with(mystruct()) { code; } calls struct destructor before code | ||||
|---|---|---|---|---|
| ||||
Is this a bug? I'm very puzzled; it seems that the destructor for struct mystruct is called pre-maturely. It should be after the 'in call(): X 12, Y 0, Z 9" line, should it not?
Using DMD64 D Compiler v2.062 on OSX 10.6.8 and Linux x86_64
Output is:
$ dmd -run named14.d
start of main
in mystruct dtor: X 0, Y 0, Z 0
top of with block
in call(): X 12, Y 0, Z 9
end of main
//code:
import std.stdio;
void main(string[] arg) {
writeln("start of main ");
with(mystruct()) {
writeln("top of with block");
x=12;
z=9;
call();
}
writeln("end of main ");
}
struct mystruct
{
int x, y, z;
~this() {
writefln("in mystruct dtor: X %s, Y %s, Z %s", x, y, z );
}
string call() {
writefln("in call(): X %s, Y %s, Z %s", x, y, z );
return "yo";
}
}
| ||||
March 23, 2013 Re: bug or not? with(mystruct()) { code; } calls struct destructor before code | ||||
|---|---|---|---|---|
| ||||
Posted in reply to J | On 3/23/13, J <not_avail@notavailable.com> wrote: > Is this a bug? It's a known bug: http://d.puremagic.com/issues/show_bug.cgi?id=8269 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply