On Apr 10, 2012, at 8:57 PM, Walter Bright <[email protected]> wrote:

> Our D solution, disallowing rvalue references, is technically sound but as 
> we've discussed here is a usability disaster, and auto ref isn't going to cut 
> it. We figured a solution is:
> 
> *** Allow rvalue references, however, disallow any implicit conversions of 
> the literal's type in the process of taking a reference to it. ***
> 
> That takes care of 1 and 2. The solution to 3 is a bit more subtle. Some 
> people have wondered why the D compiler can create reference types itself, 
> but does not allow the user to outside of function parameters and foreach 
> variables. This is the reason why. References, in order to be safe, must not 
> be allowed to escape a scope. They can only be passed downward to enclosed 
> scopes, and returned from functions where the return value is checked. Also, 
> one cannot take the address of a reference. I think this closes the holes.
> 
> With all that, I intend to once again allow struct literals to be lvalues for 
> 2.059. Somewhat later, also allow references to other literals like 0 and 5.6.

Sounds like a good change.

Just to be clear, ultimately all literals will be rvalues? Can rvalues be 
passed as const ref but not ref? I would assume the answer to both would be 
'yes'.

While I have no plans to use it, what mechanism, if any, will allow escaping 
the address? Usually, casts are the back door, but I don't believe that works 
in this case.
_______________________________________________
dmd-beta mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-beta

Reply via email to