Bug 4494 – ICE(cod1.c) Array literal filled with results of void function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-07-23T09:59:00Z
Last change time
2011-06-29T00:57:54Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-07-23T09:59:30Z
void foo() {} void main() { [foo]; } Dmd 2.047 prints: Internal error: ..\ztc\cod1.c 2650
Comment #1 by ibuclaw — 2011-01-01T11:21:49Z
Changing platform to All (affects Linux too). Similar code: void[] p = [cast(void)42]; As of DMD-2.051, now prints: Internal error: ../ztc/cod1.c 3057
Comment #2 by ibuclaw — 2011-04-11T14:39:36Z
diff --git a/src/expression.c b/src/expression.c index 9d116b9..1bd9e42 100644 --- a/src/expression.c +++ b/src/expression.c @@ -3200,6 +3200,10 @@ Expression *ArrayLiteralExp::semantic(Scope *sc) type = t0->arrayOf(); //type = new TypeSArray(t0, new IntegerExp(elements->dim)); type = type->semantic(loc, sc); + + if (type->nextOf()->ty == Tvoid) + error("array literal of type void[] has no value"); + return this; }
Comment #3 by ibuclaw — 2011-04-11T14:44:50Z
Maybe if (type->nextOf()->ty == Tvoid) error("%s of type void[] has no value", toChars()); Is a better error message (I really am no good at writing them :)
Comment #4 by ibuclaw — 2011-04-14T04:36:55Z
Oops, previous patch didn't take into account that empty '[]' array literals are allowed to be void. diff --git a/src/expression.c b/src/expression.c index 9d116b9..1e68ce7 100644 --- a/src/expression.c +++ b/src/expression.c @@ -3197,6 +3197,9 @@ Expression *ArrayLiteralExp::semantic(Scope *sc) Type *t0; elements = arrayExpressionToCommonType(sc, elements, &t0); + if (elements->dim > 0 && t0->ty == Tvoid) + error("array literal %s has no value", toChars()); + type = t0->arrayOf(); //type = new TypeSArray(t0, new IntegerExp(elements->dim)); type = type->semantic(loc, sc);
Comment #5 by kennytm — 2011-05-05T11:45:10Z
*** Issue 5929 has been marked as a duplicate of this issue. ***
Comment #6 by bugzilla — 2011-06-29T00:57:54Z