This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
C++: Is this a bug with throw and -fomit-frame-pointer?
- To: gcc at gcc dot gnu dot org
- Subject: C++: Is this a bug with throw and -fomit-frame-pointer?
- From: "George T. Talbot" <george at moberg dot com>
- Date: Tue, 19 Oct 1999 20:54:22 +0000
- Organization: Moberg Research, Inc.
I've got a short C++ test program which enters a try { } block, then
calls some C code. The C code calls some C++ code (via a function
pointer) in the test program which throws an exception. If the code in
the try {} block calls the C code directly, then the catch () { }
handler is invoked. However when I compile the files a certain way, and
the try{} block calls a C++ function, then calls the C function to cause
the exception, the program calls abort() because it can't find the catch
handler.
If I compile the files like this:
gcc -fexceptions -fomit-frame-pointer callit.c -c -o callit.o
g++ throwa.c callit.o -o die
The program will exit by calling abort().
If I compile the files like this:
gcc -fexceptions -fomit-frame-pointer callit.c -c -o callit.o
gcc -fomit-frame-pointer throwa.c callit.o -o live
The program executes to completion.
What's going on here? I believe this to be a bug--I believe that throw
should be able to follow the stack, even when compiled as above. Is
this the case?
I'm using Linux Mandrake 6.1 on x86. I've installed GCC 2.95.1 and am
using that for this test, rather than egcs 1.1.2.
Thanks for your time.
--
George T. Talbot
<george@moberg.com>
--------------------- cut here: callit.c
--------------------------------
static void (*function) (void);
void callthis(void (*f) (void))
{
function = f;
}
void dome(void)
{
function();
}
--------------------- cut here: throwa.c
--------------------------------
#include <iostream.h>
class throwa
{
public:
throwa(void) { };
~throwa() { };
};
extern "C" void callthis(void (*f) (void));
extern "C" void dome(void);
void throwthething(void)
{
cout << "Gonna throw one." << endl << flush;
throw throwa();
}
void again(void)
{
dome();
}
int main(int argc, char *argv[])
{
callthis(throwthething);
try
{
cout << "Before try one." << endl << flush;
dome();
}
catch (throwa)
{
cout << "First try works." << endl << flush;
}
try
{
again();
}
// Will not be caught with first compilation case.
catch (throwa)
{
cout << "Second try works." << endl << flush;
}
return 0;
}