Discussion Thread: DIP 1032--Function pointers and Delegate Parameters...--Community Review Round 1

Steven Schveighoffer schveiguy at gmail.com
Fri Apr 3 22:07:29 UTC 2020


Continuing the discussion from 
https://forum.dlang.org/post/r688sq$2ism$1@digitalmars.com

> Delegate/functionpointer parameters do not infer safe/nogc/pure/nothrow from their use inside the function.

No of course they do not. But S.foo infers it's attributes from the 
function body. S.foo is not a template function, so I would assume this 
passes to the delegate.

Are you suggesting that:

struct S(T)
{
    T delegate() _dg;
    void foo(T delegate() dg) { _dg = dg; }
}

behaves differently than:

struct S
{
    int delegate() _dg;
    void foo(int delegate() dg) @safe pure @nogc nothrow {_dg = dg;}
}

?

in other words, in both cases, you can call from @safe pure @nogc 
nothrow context, but the parameter in the first case is T delegate() 
(with no attributes), but the second, the parameter becomes int 
delegate() @safe pure nothrow @nogc?

There needs to be a discussion of templates in the DIP, especially when 
template attribute inference can and can not affect the delegate 
attribute requirements.

-Steve


More information about the Digitalmars-d mailing list