Throwing an exception calls abort.

M

M Joonas Pihlaja

Dear c.l.c++,

I'm trying to track down a bug in a program that appears only
when throwing exceptions and the program is compiled with
optimization. The problem is that the program aborts when it
attempts to throw an exception.

Specifically, this happens using gcc 3.2.3 and the flags -O2
-fomit-frame-pointer on an up to date RHEL. Taking off
-fomit-frame-pointer makes the program run fine. On Debian Sarge
using gcc-3.3.5-8 and gcc-2.95.4 there are no problems.

Below is a short program that illustrates the problem, and I'd
like to be sure that the issue is not caused by the code. Could
someone please have a look at it and tell me if I'm missing some
C++ (non-)subtlety?

Thanks in advance,

Joonas Pihlaja


Compile with "g++ -O2 -fomit-frame-pointer". It
should produce "got exception: wtfwtfwtf?" on stderr, but aborts
instead (again, only when compiled with gcc 3.2.3 on RHEL.)

8<--------------------------
#include <iostream>
#include <string>

struct Foo {
std::string msg;
Foo(const std::string& msg) : msg(msg) {}
};

void throwit(bool cond, const std::string& msg) {
if (cond) // if you remove this line then all goes well.
throw Foo(msg);
}

int
main()
{
try {
throwit(true, "wtfwtfwtf?");
} catch (Foo &e) {
std::cerr << "got exception: " << e.msg << "\n";;
}
catch (...) {
std::cerr << "unexpected exception" << "\n";
}
return 0;
}
8<--------------------------
 
V

Victor Bazarov

M said:
[...]
Compile with "g++ -O2 -fomit-frame-pointer". It
should produce "got exception: wtfwtfwtf?" on stderr, but aborts
instead (again, only when compiled with gcc 3.2.3 on RHEL.)
[...]

Pardon my ignorance, but if you're asking about a particular compiler,
shouldn't you be asking in that compiler's newsgroup, gnu.g++.help?
 
M

M Joonas Pihlaja

M said:
[...]
Compile with "g++ -O2 -fomit-frame-pointer". It
should produce "got exception: wtfwtfwtf?" on stderr, but aborts
instead (again, only when compiled with gcc 3.2.3 on RHEL.)
[...]

Pardon my ignorance, but if you're asking about a particular compiler,
shouldn't you be asking in that compiler's newsgroup, gnu.g++.help?

You're right, I should. Thanks for the pointer to the right
newsgroup. I wanted to make sure there's nothing wrong with the
code though before "blaming the compiler."

Best Regards,

Joonas Pihlaja (toddles off to gnu.g++.help)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top