www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13850] New: mixin template accepts delegates as function

https://issues.dlang.org/show_bug.cgi?id=13850

          Issue ID: 13850
           Summary: mixin template accepts delegates as function
                    parameters
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: schuetzm gmx.net

Reported by Vlasov Roman:
http://forum.dlang.org/thread/outsrxhcechsbkniudtz forum.dlang.org

import std.stdio;

mixin template Template(void function() func1, void function() 
func2) {

    void     to() {
        func1();
        func2();
    }
};

class SomeClass {
    mixin Template!(&func, &func23);

    void func() {
        writeln("First function!");
    }

    void func23() {
        writeln("First function!");
    }

    void toTemplate() {
        to();
    }
}

void main() {
    SomeClass a = new SomeClass();

    a.toTemplate();
}


This compiles, but segfaults at runtime, because the delegates &func and
&func23 are evidently passed to Template as function pointers.

--
Dec 10 2014