Consider the following: #include <iostream.h> class Exception{ public: Exception() {} ~Exception() {} }; std::string foo(bool throwException) { if( throwException ) { throw Exception(); } else { std:: string x = "hello world"; return x; } } int main(int argc, char** argv) { try { const std::string & str = foo(true); } catch(...) { cout << "Caught an exception" << endl; } return 0; } Compiled it for POWERPC target and upon execution, it segmentation faults and dumps a core. From the core, it is trying to delete the std::string object pointed at by str (reference to string to be returned from foo) while unwinding the stack. The same results are obtained if any of the STL classes are used. Everything works fine on x86 targets. It seems that the gcc compiler is breaching ISO/ISE 14882:2003 12.2/5 upon throw of an exception. Thanks
How is gcc configured? And which PPC target, linux, or just elf?
I am going to assume eabi, if not please reopen this bug, other wise this is a dup of bug 10778 which I am closing this one. *** This bug has been marked as a duplicate of 10778 ***
BTW, you are trying to bind the const reference to a temporary. That doesn't sound very good... W.
It is not the same as 10778. Host is linux on powerpc target machine. Compiled with options: -DLINUX -D_SVID_SOURCE=1 -D_BSD_SOURCE=1 -D_ISOC99_SOURCE=1 -D_GNU_SOURCE=1 -mpowerpc -pthread As per ISO/ISE 14882:2003 12.2/5, when a reference is bound to temporary, the temporrary remains in scope till the reference is in scope. It would seem that the gcc 3.3.1 tries to delete the temporary object refered to by a const reference upon unwinding the stack - when it should not be attempting to delete that object. IMPORTANT NOTE: Happens only when STL is involved and on POWERPC only.
I should note this works on powerpc-apple-darwin.
As Rajan correctly points out, the code is valid of course. Sorry for the confusing. W.
testcase passes with 3.3-hammer, 3.4.1 and 3.5.0 powerpc-linux and powerpc64-linux
Closing as fixed then.