Bug 5469 – Limitation when instantiating templates in the context of a function

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2011-01-20T12:27:00Z
Last change time
2013-10-09T05:56:39Z
Keywords
ice, rejects-valid
Assigned to
nobody
Creator
jens.k.mueller

Comments

Comment #0 by jens.k.mueller — 2011-01-20T12:27:09Z
The following code does not compile (tried with dmd v2.050 on Linux). import std.functional; import std.algorithm; void main() { auto numbers = [0, 1, 2, 3, 4, 5]; bool var = true; bool returnVar(uint a) { return var; } alias not!(returnVar) notReturnVar; //bool notReturnVar(uint a) { return not!returnVar(a); } // workaround filter!(returnVar)(numbers); filter!(notReturnVar)(numbers); // does not compile } It fails with: /path/to/src/phobos/std/algorithm.d(854): Error: constructor std.algorithm.Filter!(not,int[]).Filter.this cannot get frame pointer to not /path/to/src/phobos/std/algorithm.d(866): Error: function std.algorithm.Filter!(not,int[]).Filter.popFront cannot get frame pointer to not It has problems getting the frame pointer to the template function not!(returnVar). As far as I understand it. A workaround is to define a non-template function.
Comment #1 by braddr — 2011-02-06T15:39:27Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #2 by kennytm — 2011-04-26T12:30:34Z
IMO this is definitely not just an enhancement request. The code *should* compile. Also, as of current git master the code ICE with Internal error: toir.c 190 Probably related to issue 4504 or issue 5499.
Comment #3 by kennytm — 2011-05-27T20:22:16Z
*** Issue 6065 has been marked as a duplicate of this issue. ***
Comment #4 by hoganmeier — 2012-01-12T19:23:47Z
I get std/algorithm.d(1086): Error: template test.main.not!(returnVar).not(T...) if (is(typeof(!unaryFun!(pred)(args))) || is(typeof(!binaryFun!(pred)(args)))) does not match any function template declaration std/algorithm.d(1086): Error: template test.main.not!(returnVar).not(T...) if (is(typeof(!unaryFun!(pred)(args))) || is(typeof(!binaryFun!(pred)(args)))) cannot deduce template function from argument types !()(int)
Comment #5 by lovelydear — 2012-04-20T09:30:13Z
On 2.059 Win32, I get a similar result as in comment 2 PS E:\DigitalMars\dmd2\samples> rdmd -w bug.d Internal error: toir.c 178
Comment #6 by andrej.mitrovich — 2013-02-09T13:08:17Z
DMD 2.062 git-head now crashes without giving any errors. The cause of the crash: void markAsNeedingClosure(Dsymbol *f, FuncDeclaration *outerFunc) { int x = 0; for (Dsymbol *sx = f; sx != outerFunc; sx = sx->parent) { FuncDeclaration *fy = sx->isFuncDeclaration(); if (fy && fy->closureVars.dim) { /* fy needs a closure if it has closureVars[], * because the frame pointer in the closure will be accessed. */ fy->requiresClosure = true; } } } 'sx' is never checked if it's null, the for loop might have to be: for (Dsymbol *sx = f; sx /* <- added */ && sx != outerFunc; sx = sx->parent)
Comment #7 by bugzilla — 2013-10-08T23:28:59Z
Compiles without error on 2.064 head.
Comment #8 by andrej.mitrovich — 2013-10-09T05:56:39Z
(In reply to comment #7) > Compiles without error on 2.064 head. P.S. It looks like it was deliberately fixed, the `sx` check is in git-head.