structs are now lvalues - what is with "auto ref"?

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 24 10:49:20 PST 2012


On Monday, December 24, 2012 13:45:10 Andrei Alexandrescu wrote:
> The very binding of rvalues to const ref would allow that breakage. We
> can't allow that to happen.

But it's only bound for the length of the statement. After that, the binding 
can no longer exist (as the binding was a function parameter). And as I 
understand it, temporaries only go out of scope once the statement has 
completed. So,

foo(bar(min(5, 7)));

wouldn't be a problem no matter what bar or foo did, because no reference to 
5, 7, or the return values of any of the functions could be kept. It's being 
able to do

const int& i = foo(bar(min(5, 7)));

which would allow a reference to be kept around, which D disallows.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list