structs are now lvalues - what is with "auto ref"?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Dec 24 13:08:36 PST 2012
On 12/24/12 1:49 PM, Jonathan M Davis wrote:
> 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.
Actually D's rules are different from C++'s in that regard; Walter
mentioned D is more sanguine about destroying data. I'll check with him.
> 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.
I now see what you mean, thanks. We need to disallow taking the address
of that ref, but that's already planned.
Andrei
More information about the Digitalmars-d-learn
mailing list