August 07, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1404

           Summary: Link failure with template mixin and function literal
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: stephan@kochen.nl


When passing a function literal to a template such as:

template Foo(alias condition)
{
    bool invert()
    {
        return !condition();
    }
}

.. the linker will fail if that template is mixed into a class. For example:

class Bar
{
    mixin Foo!(function { return false; });
}

int main(char[][] args)
{
    auto baz = new Bar();

    if (baz.invert())
        return 0;
    else
        return 1;
}

Compiling this results in the following error:

$ dmd invertfail.d
gcc invertfail.o -o invertfail -m32 -Xlinker -L/usr/local/bin/../lib -lphobos
-lpthread -lm
invertfail.o:(.rodata+0x2c): undefined reference to
`_D10invertfail3Bar14__funcliteral1MFZb'
collect2: ld gaf exit-status 1 terug
--- errorlevel 1

However, the test case compiles and runs properly when instead the template is mixed directly into the main procedure. So this is specific the mixing into a class.


--