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

Walter Bright newshound2 at digitalmars.com
Sat Apr 4 07:12:33 UTC 2020


On 4/3/2020 3:07 PM, Steven Schveighoffer wrote:
> 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;}
> }
> 
> ?

Yes. (Otherwise the inference would have to be iterative, which I'd really like 
to avoid.)

> 
> 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.

Your example is a good one, and I'll include it.



More information about the Digitalmars-d mailing list