<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Apr 21, 2014, at 12:21 PM, suyog sarda <<a href="mailto:sardask01@gmail.com">sardask01@gmail.com</a>> wrote:<br><div><blockquote type="cite"><div dir="ltr">Ok. sorry for my silly question above. i tested the code for the question i had, and it seems that destructor of all temporaries <div>as well as other objects created before the current line are being called when exception occurs, except the destructor of the </div>

<div>outermost object. </div><div><br></div><div>From the discussion in the link shared in the previous mail and the results of the test case, i conclude that for </div><div>clang, outermost object <i>temp </i>of class <i>b </i>is not considered constructed until all the inner temporaries are destroyed.<br>
</div>
<div><br></div><div>Since the outermost 'temp' is considered yet to be constructed fully, its destructor is not pushed in '<i>EHStack</i>'. </div><div>As a result whenever exception occurs in the destructor of temporaries, the EHStack does not contain destructor of outermost</div>

<div>object and hence its cleanup doesn't take place. </div><div><br></div><div>Please correct me if i am wrong? Also, while debugging i came across, following piece of code,</div><div><br><pre style="font-size:13px;background-color:rgb(245,245,245);margin:4px 8px 4px 2px;font-family:Fixed,monospace;padding:4px 6px;border:1px solid rgb(204,204,204)"><i><span style="color:rgb(96,64,32)">void</span> <a href="http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#a079ab0affd32c3e7d992d8421776b732" style="color:rgb(0,0,255);text-decoration:none" target="_blank">CodeGenFunction::EmitCXXTryStmt</a>(<span style="color:rgb(0,128,0)">const</span> <a href="http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html" style="color:rgb(0,0,255);text-decoration:none" target="_blank">CXXTryStmt</a> &<a href="http://clang.llvm.org/doxygen/AnalysisBasedWarnings_8cpp.html#a33dc45a03958a0bf07b5da2dec4db648" style="color:rgb(0,0,255);text-decoration:none" target="_blank">S</a>) {
        <a href="http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ae064b29757ae2b6085d4df62ea2df530" style="color:rgb(0,0,255);text-decoration:none" target="_blank">EnterCXXTryStmt</a>(S);
        <a href="http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ab625dabfdcc8082335d64c4cbd009ef0" style="color:rgb(0,0,255);text-decoration:none" target="_blank">EmitStmt</a>(S.<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html#a0b14fc308d0e5f78e4f2bd425fc308da" style="color:rgb(0,0,255);text-decoration:none" target="_blank">getTryBlock</a>());
        <a href="http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ac1f782050e59094db58fbbd1b9e3f8c1" style="color:rgb(0,0,255);text-decoration:none" target="_blank">ExitCXXTryStmt</a>(S);
 }</i></pre><br></div><div class="gmail_extra"> <br>which after several function calls in between leads me to below (for init-temp1.C test code) :<br><br><i>CodeGenFunction::emitAutoVarTypeCleanup</i><br>{<br>.....<br><i>// Use an EH cleanup in array destructors iff the destructor itself<br>
  // is being pushed as an EH cleanup.<br>  bool useEHCleanup = (cleanupKind & EHCleanup);<br>  EHStack.pushCleanup<DestroyObject>(cleanupKind, addr, type, destroyer,<br>                                     useEHCleanup);</i><br>
}<br><br></div><div class="gmail_extra">At this point the destructor is pushed to EHStack.<i> </i>When i traced the code for init-temp1.C, i hit the <i>EHStack.pushcleanup </i>function above<i>, </i>still the destructor of outermost object is not being called. <br>
<br></div><div class="gmail_extra">Can someone please help me if i am looking at right place? If my analysis for clang is right - outermost object not considered created until innermost temporaries are destroyed - where should i look to correct this problem?<br>
<br></div><div class="gmail_extra">If by design, clang doesn't consider outermost object to be created until inner temporaries are destroyed, would this be a resource leak<i> </i>(i don't think it is leak, as the object is yet to be constructed, hence no destruction required)?<br>
<br></div><div class="gmail_extra">Your help would be highly appreciated.<i>  <br></i></div></div></blockquote><div><br></div></div>If the constructor has completed, the destructor needs to be called later.  IIRC, the problem that makes solving this so annoying is that, as soon as one temporary destructor terminates abnormally, the next thing to destroy is always the local variable (since it was constructed most recently), and only then proceeding to destroy the remainder of the temporaries.<div><br></div><div><div>That is, if we’re creating local variable X, and we needed to construct temporaries A, B, and C to do that, then if C’s destructor throws, we need to destroy X, then B, then A; and if B’s destructor throws, we need to destroy X before A.</div></div><div><br></div><div>This is not achievable with a simple stack mechanism.</div><div><br></div><div>John.</div></body></html>