Destructor order
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Oct 22 16:11:14 PDT 2014
    
    
  
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.
Ali
    
    
More information about the Digitalmars-d-learn
mailing list