Missed scope guard statements

Max Samukha samukha at voliacable.com.removethis
Thu Mar 6 02:37:04 PST 2008


On Wed, 05 Mar 2008 16:26:27 -0500, Steve Jackson
<sjackso at cs.wisc.edu> wrote:

>(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.

Looks like a bug but makes no sense in a real application anyway?

if( true ) scope(exit) writef("hello");
is semantically the same as simply
if( true ) writef("hello");

Do you have any use case for that?
 


More information about the Digitalmars-d-bugs mailing list