[Issue 21521] New: Cannot state ref return for delegates and function pointers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 3 02:46:31 UTC 2021


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

          Issue ID: 21521
           Summary: Cannot state ref return for delegates and function
                    pointers
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: qs.il.paperinik at gmail.com

Currently, the grammar does not allow `ref` to occur in the rhs of IsExpression
and parameter types. There is no way to express that a function requires its
function pointer/delegate parameter to return by reference without using a
helper alias:

void f(ref int delegate() dg)
{
    static assert(!__traits(isRef, dg)); // fails, dg is ref, not its return
}


void f(int delegate() ref dg) // invalid syntax: found `ref` when expecting 
{ }

Same for testing whether DG is a fp or delegate returning by ref:
    is(DG : ref int delegate()) // invalid syntax
    is(DG : int delegate() ref) // invalid syntax

Workaround:
    alias RefFunctionPointer(T, Args...) = ref T function(Args);
    alias RefDelegate(T, Args...) = ref T delegate(Args);

The workaround has severe limitations such as attributes and parameter storage
classes.

--


More information about the Digitalmars-d-bugs mailing list