[Issue 2744] wrong init tocbuffer of forstatement

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 19 05:08:03 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2744





------- Comment #1 from davidl at 126.com  2009-03-19 07:08 -------
err, the patch was wrong. 

simple testcase:
template V(T)
{
void func()
{
        for(int i,j; i<3;i++)
        {
        }
}
}


with a little bit research:
hdrgen.h, 25:
    int emitInst;
+++ int inInit;
    struct


declaration.c, 1103 becomes:
        buf->writestring("__thread ");
#endif
        if(!hgs->FLinit.decl && type)
        {
                type->toCBuffer(buf, ident, hgs);
        }
        else
                buf->writestring(ident->toChars());

    if (init)
    {   buf->writestring(" = ");
        init->toCBuffer(buf, hgs);
    }
        if(hgs->inInit) 
                buf->writeByte(',');
        else
                buf->writeByte(';');

statement.c 

void CompoundStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
        if (!hgs->FLinit.init)
        {
    for (int i = 0; i < statements->dim; i++)
    {   Statement *s = (Statement *) statements->data[i];
        if (s)
            s->toCBuffer(buf, hgs);
    }
        }
        else
        {
        hgs->FLinit.decl = 0;
        hgs->inInit = 1;
        Statement *s1 = (Statement *) statements->data[0];
        if (s1)
            s1->toCBuffer(buf, hgs);
        hgs->FLinit.decl = 1;
    for (int i = 1; i < statements->dim-1; i++)
    {   Statement *s = (Statement *) statements->data[i];
        if (s)
            s->toCBuffer(buf, hgs);
    }
        hgs->inInit = 0;
        s1 = (Statement *) statements->data[statements->dim-1];
        if (s1)
            s1->toCBuffer(buf, hgs);
        hgs->FLinit.decl = 0;
    }   
}


-- 



More information about the Digitalmars-d-bugs mailing list