Missed scope guard statements

Robert Fraser fraserofthenight at gmail.com
Wed Mar 5 14:54:35 PST 2008


Hi Steve,

The place to report issues is here: http://d.puremagic.com/issues/ . You 
need to register a bugzilla account, then click "New" on the bottom bar, 
then "D", and enter a world of happiness and bug reporting.

I would guess that in both cases, that should produce the output:

  world
hello

Since the writefln("hello") is within a scope-exit, so should only fire 
as part of the function exit condition.

Steve Jackson 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.


More information about the Digitalmars-d-bugs mailing list