<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div class="h5">
<div><br></div></div></div>Your proposed change causes the destructor for the auto object to be run if the initializer throws, even if the auto var constructor hasn’t been run yet.</div><span class="HOEnZb"><font color="#888888"><div>
<br></div></font></span></div></blockquote><div><br></div><div>My bad, i got carried away with specifics to the problem and didn't look at whole picture. </div><div><br></div><div>Ok, right now, cleanup code of temporaries is getting emitted before entry of auto variable gets added in the EHStack which is causing resource leak. </div>
<div>This is because, scope of the temporaries gets over (which causes their cleanup code to emit) after initialization but before adding EHStack entry of auto variable.</div><div>If the temporary storage duration is extended till full expression, then it will be easy to use EHStack. </div>
<div><br></div><div>For auto variable emission there are three steps involved (Correct me if i am wrong) :</div><div><br></div><div>1. EmitAlloca - emit code for alloca which will allocate memory</div><div>2. EmitInit - emit code for initializing the object which involves evaluating the subexpression</div>
<div>3. EmitCleanup - EmitCleanup code for constructed object</div><div><br></div><div>The problem is after allocating memory successfully in 1st step, if something goes wrong in initializing (exception in temporary destructor), the memory allocated in 1st step is not cleaned because it happens in 3rd step which is never visited.  </div>
<div><br></div><div>Is their any other way to resolve this issue? Or only extending storage duration will help in easy implementation?</div><div>   </div></div>-- <br>With regards,<br>Suyog Sarda<br>
</div></div>