On Wednesday, 22 October 2014 at 23:11:14 UTC, Ali Çehreli wrote:
On 10/22/2014 04:05 PM, eles wrote:
> And the compiler swallows this without even barking?
The compiler must obey an alias this inside Scoped.
I've thinking for a way do disallow this but haven't been able
to spend much time on it today.
> Why Scoped!A is convertible to A, then?
So that Scoped!A can conveniently be used as an A.
> And what the resulting A-typed variable contains if the object
> gets destroyed.
Note that the A is not the object but the class reference to
it. The 'alias this' hands out a reference to the object that
is on the stack. The reference is valid when that occurs. Then,
the compiler destroys the temporary Scoped!A object as it
should, leaving behind a dangling reference.
There must be a way to disallow this.
Yet another use case for borrowing.