D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3432 - ICE(e2ir.c): casting template expression
Summary: ICE(e2ir.c): casting template expression
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2009-10-21 07:13 UTC by Don
Modified: 2014-02-15 13:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-10-21 07:13:49 UTC
void main() {
    void fun(T)() {}
    int x = cast(int)fun;
}
----

fun(T)
Internal error: e2ir.c 644
Comment 1 Don 2009-10-21 07:16:59 UTC
Oops, local template functions seem to be legal in D2. I didn't realize that. So this is valid code.
Comment 2 Don 2009-10-22 01:35:53 UTC
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 Leandro Lucarella 2009-10-31 22:47:13 UTC
SVN commit: http://www.dsource.org/projects/dmd/changeset/232
Comment 4 Walter Bright 2009-11-06 11:32:07 UTC
Fixed dmd 1.051 and 2.036