Thread overview
[Issue 2744] New: wrong init tocbuffer of forstatement
Mar 19, 2009
d-bugmail
Mar 19, 2009
d-bugmail
Mar 20, 2009
d-bugmail
Apr 01, 2009
d-bugmail
March 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2744

           Summary: wrong init tocbuffer of forstatement
           Product: D
           Version: 1.041
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: davidl@126.com


line 1126:
       if (hgs->FLinit.decl > 0)
            buf->writebyte(';');
should be:
        if (hgs->FLinit.decl > 0)
            buf->writebyte(',');


-- 

March 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2744





------- Comment #1 from davidl@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;
    }
}


-- 

March 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2744





------- Comment #2 from davidl@126.com  2009-03-20 07:57 -------
simple testcase:
template T(t){
        void func(){
                        for ( auto cmp = t.predicate.data_str.ptr,
                            cmpend = cmp + t.predicate.data_str.length;
                            cmp < cmpend; ++cmp )
                        {

                        }
        }
}

void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
        if(!hgs->FLinit.decl)
        {
    if (storage_class & STCconst)
        buf->writestring("const ");
    if (storage_class & STCstatic)
        buf->writestring("static ");
    if (storage_class & STCauto)
        buf->writestring("auto ");
        }

last patch doesn't solve the auto storage class issue.


-- 

April 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2744


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla@digitalmars.com  2009-04-01 13:49 -------
Fixed DMD 1.042 and 2.027


--