www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Perhaps here is a critical bug of scope statement and scoped variable (RAII), please help me to veriry it

reply redsea <redsea 163.com> writes:
error: 
    scope(success)  not called, and RAII variable not destruct correctly.

compiler:  Digital Mars D Compiler v1.033
come from tango-0.99.7-bin-linux-dmd.1.033.tar.gz

code:

import tango.io.Stdout;
alias Stdout ot;

scope class Indent
{
    this()
    {
        ot("<<<").newline;
    }
    ~this()
    {
        ot(">>>").newline;
    }
}

void doScan(int a)
{
    ot("doScan {{{").newline;

    scope(exit)
        ot.flush;
    scope(failure)
        ot("doScan failure }}}").newline;
    scope(success)
        ot("doScan ok }}}").newline;

    scope auto ident__doScan__ident = new Indent();

    if (a == 0 )
        return;
}


void main()
{
    for (int i=0; i<8;i++)
        doScan(0);
}


output:

doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
doScan {{{
<<<
Dec 16 2008
next sibling parent redsea <redsea 163.com> writes:
If comment the following:

    if (a == 0 )
        return;

output would be ok:

[tmp]root ./test
doScan {{{
<<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



Dec 16 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Wed, Dec 17, 2008 at 12:02 AM, redsea <redsea 163.com> wrote:
 error:
    scope(success)  not called, and RAII variable not destruct correctly.

 compiler:  Digital Mars D Compiler v1.033
 come from tango-0.99.7-bin-linux-dmd.1.033.tar.gz

 code:

 import tango.io.Stdout;
 alias Stdout ot;

 scope class Indent
 {
    this()
    {
        ot("<<<").newline;
    }
    ~this()
    {
        ot(">>>").newline;
    }
 }

 void doScan(int a)
 {
    ot("doScan {{{").newline;

    scope(exit)
        ot.flush;
    scope(failure)
        ot("doScan failure }}}").newline;
    scope(success)
        ot("doScan ok }}}").newline;

    scope auto ident__doScan__ident = new Indent();

    if (a == 0 )
        return;
 }


 void main()
 {
    for (int i=0; i<8;i++)
        doScan(0);
 }

I just tried with DMD 1.037, and I get the correct output: doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



doScan {{{ <<<



Dec 16 2008