www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - with statement doesn't call struct destructor?

reply simendsjo <simen.endsjo pandavre.com> writes:
import std.stdio;
void main() {
     struct S {
         this(bool a) { writeln(" this"); }
         ~this() { writeln(" ~this"); }
     }

     writeln("scoped:");
     {
         auto s = S(true);
     }

     writeln("with:");
     with(S(true)) {
     }
}

Output:

scoped:
  this
  ~this
with:
  this
Jun 08 2011
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On 2011-06-08 13:31, simendsjo wrote:
 import std.stdio;
 void main() {
 struct S {
 this(bool a) { writeln(" this"); }
 ~this() { writeln(" ~this"); }
 }
 
 writeln("scoped:");
 {
 auto s = S(true);
 }
 
 writeln("with:");
 with(S(true)) {
 }
 }
 
 Output:
 
 scoped:
 this
 ~this
 with:
 this

Report it on bugzilla. Walter has been fixing issues with destructors for temporaries lately. They've been buggy for a while. A fair bit of the problem was fixed in dmd 2.053 but not all of it. If you're not using 2.053, then that's probably why the code is broken. If you are using 2.053, then Walter needs to be aware that that particular use case hasn't been fixed yet. - Jonathan M Davis
Jun 08 2011
parent simendsjo <simen.endsjo pandavre.com> writes:
On 08.06.2011 23:14, Jonathan M Davis wrote:
 On 2011-06-08 13:31, simendsjo wrote:
 import std.stdio;
 void main() {
 struct S {
 this(bool a) { writeln(" this"); }
 ~this() { writeln(" ~this"); }
 }

 writeln("scoped:");
 {
 auto s = S(true);
 }

 writeln("with:");
 with(S(true)) {
 }
 }

 Output:

 scoped:
 this
 ~this
 with:
 this

Report it on bugzilla. Walter has been fixing issues with destructors for temporaries lately. They've been buggy for a while. A fair bit of the problem was fixed in dmd 2.053 but not all of it. If you're not using 2.053, then that's probably why the code is broken. If you are using 2.053, then Walter needs to be aware that that particular use case hasn't been fixed yet. - Jonathan M Davis

http://d.puremagic.com/issues/show_bug.cgi?id=6128
Jun 08 2011