On Apr 10, 2012, at 5:57 PM, Walter Bright wrote:

> I couldn't remember what the big problem was with rvalue references, and so I 
> spent some time on the phone talking with Andrei about what exactly the 
> problem is. They are:
> 
> 1.
> C++:
>  int i;
>  double& d = i;

I'm shocked that this is legal.  Why allow implicit conversions when assigning 
to a reference?

> Now d is referring to a temporary that has gone out of scope. This is, of 
> course, a memory corrupting disaster, const ref or no const.
> 
> 3. This one is a more general problem with references, that of escaping 
> references to locals:
>  double& d;
>  void foo(double x, double y) {
>     d = x + y;
>  }

In C++, the temporary would persist if the reference were const, correct?  How 
is this implemented, anyway?

> 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.

Seems entirely reasonable.
_______________________________________________
dmd-beta mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-beta

Reply via email to