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?

If taking the address of a ref is disallowed, then the above problem goes away. &fun, in all its variants, takes the address of the function.

Reply via email to