<div dir="ltr"><div>Hi all,<br><br></div><div>This is a test g++ test case for checking correct exception handling.<br><br></div><div><i>#ifdef __GXX_EXPERIMENTAL_CXX0X__<br>#define NOEXCEPT_FALSE noexcept (false)<br>#else<br>
#define NOEXCEPT_FALSE<br>#endif<br><br>extern "C" void abort ();<br> <br>int thrown;<br><br>int as;<br>struct a {<br> a () { ++as; }<br> ~a () NOEXCEPT_FALSE { --as; if (thrown++ == 0) throw 42; }<br>};<br> <br>
int f (a const&) { return 1; }<br>int f (a const&, a const&) { return 1; }<br><br>int bs;<br>int as_sav;<br>struct b {<br> b (...) { ++bs; }<br> ~b () { --bs; as_sav = as; }<br>};<br><br>bool p;<br>void g()<br>
{<br> if (p) throw 42;<br>}<br><br>int main () {<br> thrown = 0;<br> try {<br> b tmp(f (a(), a()));<br><br> g();<br> } <br> catch (...) {}<br><br> // We throw when the first a is destroyed, which should destroy b before<br>
// the other a.<br> if (as_sav != 1)<br> abort ();<br><br> thrown = 0;<br> try {<br> b tmp(f (a()));<br><br> g();<br> } <br> catch (...) {}<br> <br> if (bs != 0)<br> abort ();<br>} </i><br clear="all">
</div><div><br></div><div>This Test Case aborts on ARM as well as X86 with clang latest trunk while with g++ no aborts are seen .<br><br></div><div>Here, when first temporary object '<i>a'</i> gets destroyed, its destructor is called where we throw an exception. This should immediately call destructor of <i>'b'</i> and before calling constructor of second temporary object <i>'a'</i>. Instead, with clang, it is waiting for second temporary object <i>'a'</i> to get destroyed and then calling its own destructor.<br>
<br></div><div>In my opinion, the compiler is not generating correct landing pad for the exception. Can someone please help in validating this reason? If it is a genuine bug then i will file a bug and try to work out solution for it. <br>
</div><div><br>-- <br>With regards,<br>Suyog Sarda<br></div>
</div>