www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1404] New: Link failure with template mixin and function literal


           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;
        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
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

Aug 07 2007