Missed scope guard statements

Robert Fraser fraserofthenight at gmail.com
Thu Mar 6 18:13:16 PST 2008


Max Samukha wrote:
> 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?

Compile-time values could evaluate to true, and compile-time code 
generation could very easily create code that would seem silly to write 
directly. So it's a valid problem.


More information about the Digitalmars-d-bugs mailing list