[Issue 21537] New: Function pointers' attributes not covariant when referencing (delegates' are)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 9 19:20:48 UTC 2021


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 at puremagic.com
          Reporter: qs.il.paperinik at 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

--


More information about the Digitalmars-d-bugs mailing list