www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2744] New: wrong init tocbuffer of forstatement

reply d-bugmail puremagic.com writes:
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(',');


-- 
Mar 18 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2744






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;
    }   
}


-- 
Mar 19 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2744






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.


-- 
Mar 20 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2744


bugzilla digitalmars.com changed:

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





Fixed DMD 1.042 and 2.027


-- 
Apr 01 2009