[Issue 2753] Cannot declare pointer to function returning ref

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 19 10:23:51 UTC 2024


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

--- Comment #18 from Stewart Gordon <smjg at iname.com> ---
(In reply to Nick Treleaven from comment #17)
> (In reply to anonymous4 from comment #2)
>> int goo(int function() ref foo); //return byref function
> 
> Allowing that would seem to be a simple fix to the problem, except now it
> would be confusing with the `return ref` attribute. The latter didn't exist
> when you wrote that though.

I stand by what I said before.  It makes no sense to me to have the notation
for "reference to an integer" split in two like this.  To me, that notation
reads as declaring foo as a byref parameter, not as a parameter of
function-with-byref-return type.  I think most people would agree.  Hence my
earlier proposal:

> int foo(int function() ref goo);  // ref parameter
> int goo(int ref function() foo);  // ref return in parameter

Here, the 'ref' would be exactly the same as '*' for pointers and '[]' for
arrays in terms of how it is placed.  That 'ref' is a keyword rather than a
symbol shouldn't have to make any difference to this.

--


More information about the Digitalmars-d-bugs mailing list