Dear LLVM Members,<div><br><div>        The below source code from gcc test suite replicates the problem which i am facing.  When it is built with clang, it throws an <span style="background-color:rgb(255,0,0)">abort</span>(highlighted).</div>
<div>The following are my observations - </div><div><br></div><div>1. The object(tmp) is not getting destroyed immediately after the exception is thrown.  In case of Clang, the object is getting destroyed at a later point of time.</div>
<div>2. In case of gcc, the scope of the object created inside the try-catch block is limited to the block.  Once the exception is thrown, the object(tmp) is destroyed.</div><div>3. The assembly files for both clang and gcc were generated and compared, wherein the sequence of operations look similar.</div>
<div>4. I also tried the MS-Visual Studio compiler, which gives a result similar to gcc.</div><div><br></div><div><div>As per my understanding of the C++ standard, the object has to be destroyed as soon as the exception is thrown.  </div>
<div>Please let me know which is the correct behavior and suggest me the changes required.</div><div><br></div><div><br></div><div><div>Thanks & Regards,</div><div>Shivaprasad</div><div><a href="mailto:shivahms@gmail.com">shivahms@gmail.com</a></div>
</div><div><br></div><div>/******************************************************************Source Code Start*******************************************************************/</div><div>extern "C" void abort ();</div>
<div><br></div><div>int thrown;</div><div><br></div><div>int as;</div><div>struct a {</div><div>  a () { ++as; }</div><div>  ~a () { --as; if (thrown++ == 0) throw 42; }</div><div>};</div><div><br></div><div>int f (a const&) { return 1; }</div>
<div>int f (a const&, a const&) { return 1; }</div><div><br></div><div>int bs;</div><div>int as_sav;</div><div>struct b {</div><div>  b (...) { ++bs; }</div><div>  ~b ()   { --bs; as_sav = as; }</div><div>};</div>
<div><br></div><div>bool p;</div><div>void g()</div><div>{</div><div>  if (p) throw 42;</div><div>}</div><div><br></div><div><span style="background-color:rgb(255,255,102)">int main () {</span></div><div><span style="background-color:rgb(255,255,102)">  thrown = 0;</span></div>
<div><span style="background-color:rgb(255,255,102)">  try {</span></div><div><span style="background-color:rgb(255,255,102)">    b tmp(f (a(), a()));</span></div><div><span style="background-color:rgb(255,255,102)"><br></span></div>
<div><span style="background-color:rgb(255,255,102)">    g();</span></div><div><span style="background-color:rgb(255,255,102)">  }</span></div><div><span style="background-color:rgb(255,255,102)">  catch (...) {}</span></div>
<div><br></div><div>  // We throw when the first a is destroyed, which should destroy b before</div><div>  // the other a.</div><div>  if (as_sav != 1)</div><div>   <span style="background-color:rgb(255,0,0)"> abort ();</span></div>
<div><br></div><div>  thrown = 0;</div><div>  try {</div><div>    b tmp(f (a()));</div><div><br></div><div>    g();</div><div>  }</div><div>  catch (...) {}</div><div><br></div><div>  if (bs != 0)</div><div>    abort ();</div>
<div>}</div><div>/******************************************************************Source Code End*******************************************************************/</div><div><br></div><div><br></div>
</div></div>