www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21537] New: Function pointers' attributes not covariant when

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

          Issue ID: 21537
           Summary: Function pointers' attributes not covariant when
                    referencing (delegates' are)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: qs.il.paperinik gmail.com

A function pointer with attributes such as  safe cannot be referenced by a
const  system function pointer type:

    alias SysFP = void function();
    alias SafeFP = void function()  safe;

    void g(const(SysFP)*) { }

    SafeFP safeFp = { };
    g(&safeFp); // fails

The same works perfectly when you s/function/delegate the types.

This snipped gives you the full picture, also a comparison with delegates and
class inheritance: https://run.dlang.io/is/zSNArx

--
Jan 09