www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5469] New: Limitation when instantiating templates in the context of a function

reply d-bugmail puremagic.com writes:
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



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: -------
Jan 20 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Brad Roberts <braddr puremagic.com> changed:

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



---
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: -------
Feb 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Apr 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5469


kennytm gmail.com changed:

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



*** 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: -------
May 27 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5469


Trass3r <mrmocool gmx.de> changed:

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



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: -------
Jan 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5469


SomeDude <lovelydear mailmetrash.com> changed:

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



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: -------
Apr 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Feb 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 08 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5469




05:56:39 PDT ---

 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: -------
Oct 09 2013