On Mon, 04 Feb 2013 18:18:16 -0500, Walter Bright
<[email protected]> wrote:
On 2/4/2013 6:05 AM, Andrei Alexandrescu wrote:
Couldn't AddressOf use "&(" + exp + ")"?
I thought more about this. The problem remains even without @property,
due to
optional parens in function invocation. Consider:
ref int fun() { ... }
auto p1 = &fun;
auto p2 = &(fun);
auto p3 = &(fun());
What are the types of the three? The optional parens in invocation
require some
disambiguation. I think the sensible disambiguation is to have &fun
take the
address of fun and the other two take the address of fun's result.
The only time it is valid to take the address of a function's return
value is if the function returns a ref.
But I also would think that it's a suspicious practice to take the
address of a ref. We've disallowed it in other circumstances, why allow
it here? If a function intends for someone to take the address of the
return ref, shouldn't the function return a pointer instead?
I'd agree with you if we could have ref variables. In some cases, taking
the address is the ONLY option.
-Steve