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

Walter Bright newshound2 at digitalmars.com
Wed May 20 06:03:52 UTC 2020


On 4/3/2020 3:39 PM, Jonathan Marler wrote:
> Instead of delegate/function pointer parameters implicitly inheriting all the 
> attributes of the containing function, what if we made it "opt-in" with a single 
> attribute? i.e.
> 
> @safe pure nothrow @nogc
> int foo(int delegate() @inherit dg, int function() @inherit fp)
> {
>      return dg() + fp();
> }
> 
> Advantages:
> 
> 1. No code breakage
> 2. The developer sees @inherit and knows the function/delegate pointer it will 
> contain extra attributes inherited from somewhere else.
> 3. You can still support the case where you don't want any attributes.  Example 
> cases of this would be if you're not calling the pointer yourself, or, maybe the 
> function itself is nothrow but it allows the function/delegate pointers to throw 
> and catches/handles their exceptions without propogating them.

All problems can be solved by adding another attribute. Unfortunately, this 
winds up with an incomprehensible "attribute soup". The idea is to try to work 
things out without needing extra attributes.

As mentioned in DIP1032, delegates can "opt out" by being declared with an alias 
type.


More information about the Digitalmars-d mailing list