Bug 8711 – ICE with initializing function pointer with array

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-23T08:03:00Z
Last change time
2013-11-25T02:19:29Z
Keywords
diagnostic, ice, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-09-23T08:03:31Z
This is correct code: int function(int)[] foos = [x => 0]; void main() {} This wrong program is the same, but it lacks the []: int function(int) foos = [x => 0]; void main() {} DMD 2.061alpha gives on the second program: temp.d(1): Error: cannot implicitly convert expression (__lambda2) of type int function(int x) pure nothrow @safe to int(int) Error: no size for type int(int) Some problems: - The first line doesn't seem to mention that foos is not typed as an array. - The second error message lacks a line number: - I am not sure that "no size for ..." is correct. (This bug has severity 'major' as Don asked me for error messages missing line numbers.)
Comment #1 by yebblies — 2013-01-02T07:20:22Z
It is valid to initialize a pointer to T with an array of T, unless it is a function pointer. Lowering the priority because the first error _does_ have a line number, and the second is just nonsense. @@ -493,13 +493,12 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t, NeedInterpret needIn type = t; Initializer *aa = NULL; t = t->toBasetype(); switch (t->ty) { - case Tpointer: case Tsarray: case Tarray: break; case Tvector: t = ((TypeVector *)t)->basetype; break; case Taarray: // was actually an associative array literal aa = new ExpInitializer(loc, toAssocArrayLiteral()); return aa->semantic(sc, t, needInterpret); + case Tpointer: + if (t->nextOf()->ty != Tfunction) + break; default: error(loc, "cannot use array to initialize %s", type->toChars()); goto Lerr; }
Comment #2 by yebblies — 2013-11-24T05:52:25Z
Now ICEs assert func.c(181) treq->nextOf()->ty == Tfunction
Comment #3 by yebblies — 2013-11-24T05:59:27Z
Comment #4 by github-bugzilla — 2013-11-25T02:12:14Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f5afcd4f45b82cee59e248802e69906aa2293b3d Fix Issue 8711 - ICE with initializing function pointer with array https://github.com/D-Programming-Language/dmd/commit/b6b240bdc8e167da6f140570c752c57ab1ca3541 Merge pull request #2874 from yebblies/issue8711 Issue 8711 - ICE with initializing function pointer with array