Thread overview
[Issue 5469] New: Limitation when instantiating templates in the context of a function
Feb 06, 2011
Brad Roberts
Apr 26, 2011
kennytm@gmail.com
May 28, 2011
kennytm@gmail.com
Jan 13, 2012
Trass3r
Apr 20, 2012
SomeDude
Feb 09, 2013
Andrej Mitrovic
Oct 09, 2013
Walter Bright
Oct 09, 2013
Andrej Mitrovic
January 20, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5469

           Summary: Limitation when instantiating templates in the context
                    of a function
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jens.k.mueller@gmx.de


--- Comment #0 from jens.k.mueller@gmx.de 2011-01-20 12:27:09 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86


--- Comment #1 from Brad Roberts <braddr@puremagic.com> 2011-02-06 15:39:27 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5469


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code,
                   |                            |rejects-valid
                 CC|                            |kennytm@gmail.com
         OS/Version|Linux                       |All
           Severity|enhancement                 |normal


--- Comment #2 from kennytm@gmail.com 2011-04-26 12:30:34 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5469


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from kennytm@gmail.com 2011-05-27 20:22:16 PDT ---
*** Issue 6065 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool@gmx.de


--- Comment #4 from Trass3r <mrmocool@gmx.de> 2012-01-12 19:23:47 PST ---
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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5469


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #5 from SomeDude <lovelydear@mailmetrash.com> 2012-04-20 09:30:13 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-09 13:08:17 PST ---
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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |WORKSFORME


--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2013-10-08 23:28:59 PDT ---
Compiles without error on 2.064 head.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5469



--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-09 05:56:39 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------