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<--------------------------
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<--------------------------