Missed scope guard statements

Steve Jackson sjackso at cs.wisc.edu
Wed Mar 5 13:26:27 PST 2008


(This is a report of what I believe is a "new" bug in the D compiler.  I'm not sure whether this newsgroup is the appropriate place to report such things, but it is the best I have been able to find.)

While experimenting with scope guard statements, I came across some unexpected behavior.  This snippet:

{
 if( true ){ scope(exit) writef("hello"); }
 writefln(" world" );
}

Produces the output "hello world", as I expected.  However, if I remove the if statement's braces, like so:

{
 if( true ) scope(exit) writef("hello");
 writefln( " world" );
}

... then the first writef call is skipped entirely, and the output is " world".  No errors or compiler warnings are generated.

I'm using the dmd compiler v2.010 on Linux.



More information about the Digitalmars-d-bugs mailing list