Bug 3432 – ICE(e2ir.c): casting template expression

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-10-21T07:13:00Z
Last change time
2014-02-15T13:13:12Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2009-10-21T07:13:49Z
void main() { void fun(T)() {} int x = cast(int)fun; } ---- fun(T) Internal error: e2ir.c 644
Comment #1 by clugdbug — 2009-10-21T07:16:59Z
Oops, local template functions seem to be legal in D2. I didn't realize that. So this is valid code.
Comment #2 by clugdbug — 2009-10-22T01:35:53Z
Applies to D1 as well. Doesn't require nested templates. Test case (ICEs even on DMD0.175): --- void fun(T=int)(int w, int z) {} void main() { auto x = cast(void function(int, int))fun; } --- Root cause: Shouldn't be able to cast from void to anything else (except void). This patch also moves some error messages from e2ir into the front-end where they belong. ----- PATCH: expression.c, line 7423 (DMD 2.035, svn rev215): if (!to->equals(e1->type)) { e = op_overload(sc); if (e) { return e->implicitCastTo(sc, to); } + /* Cannot cast from void to anything other than void + */ + if (e1->type == Type::tvoid) { + error("'%s' is void and cannot be cast to %s", e1->toChars(), to->toChars()); + return new ErrorExp(); + } } Type *t1b = e1->type->toBasetype(); Type *tob = to->toBasetype();
Comment #3 by leandro.lucarella — 2009-10-31T22:47:13Z
Comment #4 by bugzilla — 2009-11-06T11:32:07Z
Fixed dmd 1.051 and 2.036