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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4494 - ICE(cod1.c) Array literal filled with results of void function
Summary: ICE(cod1.c) Array literal filled with results of void function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
: 5929 (view as issue list)
Depends on:
Blocks:
Reported: 2010年07月23日 09:59 UTC by bearophile_hugs
Modified: 2011年06月29日 00:57 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010年07月23日 09:59:30 UTC
void foo() {}
void main() {
 [foo];
}
Dmd 2.047 prints:
Internal error: ..\ztc\cod1.c 2650
Comment 1 Iain Buclaw 2011年01月01日 11:21:49 UTC
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 Iain Buclaw 2011年04月11日 14:39:36 UTC
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 Iain Buclaw 2011年04月11日 14:44:50 UTC
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 Iain Buclaw 2011年04月14日 04:36:55 UTC
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 kennytm 2011年05月05日 11:45:10 UTC
*** Issue 5929 has been marked as a duplicate of this issue. ***


AltStyle によって変換されたページ (->オリジナル) /