Bug 2744 – wrong init tocbuffer of forstatement

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-03-18T23:50:00Z
Last change time
2014-04-18T09:12:04Z
Assigned to
bugzilla
Creator
davidl

Comments

Comment #0 by davidl — 2009-03-18T23:50:08Z
line 1126: if (hgs->FLinit.decl > 0) buf->writebyte(';'); should be: if (hgs->FLinit.decl > 0) buf->writebyte(',');
Comment #1 by davidl — 2009-03-19T07:08:08Z
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; } }
Comment #2 by davidl — 2009-03-20T07:57:59Z
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.
Comment #3 by bugzilla — 2009-04-01T13:49:01Z
Fixed DMD 1.042 and 2.027