Bug 2399 – ICE(cgcod.c) on casting function to delegate

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-10-08T11:26:00Z
Last change time
2014-04-18T09:12:03Z
Keywords
ice-on-invalid-code, patch, wrong-code
Assigned to
bugzilla
Creator
dfj1esp02

Comments

Comment #0 by dfj1esp02 — 2008-10-08T11:26:38Z
alias void delegate() dg; void fun(){} void gun() { dg d=cast(dg)&fun; }
Comment #1 by clugdbug — 2009-05-14T02:45:00Z
If compiled with -O, this generates wrong code instead. Also applies to D1.
Comment #2 by clugdbug — 2009-05-15T00:30:01Z
Internal error: ..\backend\cgcod.c 1549 This is almost certainly related to bug 2323, bug 2672, and bug 2875.
Comment #3 by clugdbug — 2009-05-15T14:35:46Z
The root cause is in cast.c, Expression *SymOffExp::castTo(Scope *sc, Type *t). Casting from a function pointer to a delegate must be forbidden. This patch also fixes Bug 2875. ============ else if (tb->ty == Tdelegate && f->isNested()) { e = new DelegateExp(loc, new IntegerExp(0), f); e = e->semantic(sc); } + else if (tb->ty == Tdelegate) { + error("Cannot cast from function pointer to delegate"); + return this; + } else { e = new SymOffExp(loc, f, 0); e->type = t; }
Comment #4 by bugzilla — 2009-07-09T02:54:46Z
Fixed dmd 2.031