Bug 3668 – foreach over typedef'd array crashes dmd
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-01-03T15:00:00Z
Last change time
2015-06-09T01:26:47Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
spam
Comments
Comment #0 by spam — 2010-01-03T15:00:13Z
This code used to work up to version 2.031 without problems, since 2.032 it manages to crash dmd.
[CODE]
typedef byte[] Foo;
Foo bar;
foreach(value; bar){}
[/CODE]
Comment #1 by clugdbug — 2010-01-04T07:24:58Z
There's a missing toBaseType() in the Foreach code which was introduced in D2.032.
PATCH:
statement.c, line 1525, in ForeachStatement::semantic():
------
Identifier *id = Lexer::uniqueId("__aggr");
ExpInitializer *ie = new ExpInitializer(loc, new SliceExp(loc, aggr, NULL, NULL));
- VarDeclaration *tmp = new VarDeclaration(loc, aggr->type->nextOf()->arrayOf(), id, ie);
+ VarDeclaration *tmp = new VarDeclaration(loc, aggr->type->toBasetype()->nextOf()->arrayOf(), id, ie);
Expression *tmp_length = new DotIdExp(loc, new VarExp(loc, tmp), Id::length);
Comment #2 by andrei — 2010-01-04T08:47:18Z
typedef is gone.
Comment #3 by spam — 2010-01-04T09:16:23Z
huh ? it is gone ? in dmd 2.032 - 2.039 it is certainly not, otherwise the compiler would complain using it (puting this crash aside). since when is typedef gone and why ?
Comment #4 by spam — 2010-01-04T09:19:18Z
whatever is meant by "typedef is gone" the compiler should not crash under any circumstance. feel free to change the keywords to ice-on-invalid if that is the actual case.