Exception handling bug (2): gcc-2.95.2 (unfixed from gcc-2.95.1)
Chris Rankin
rankinc@zip.com.au
Wed Oct 27 03:22:00 GMT 1999
Hi,
The following code core-dumps when compiled with gcc-2.95.2,
i586-pc-linux-gnu using binutils 2.9.5. The problem seems to be
triggered when the -fomit-frame-pointer option is active.
Cheers,
Chris.
#include <string>
#include <iostream>
using namespace std;
/******************************************************
* class Exception
*/
class Exception {
private:
string m_msg;
public:
Exception(const string &msg) : m_msg(msg) {}
const string& get_msg() const { return m_msg; }
};
void throw_Exception(const string &msg) __attribute__((noreturn));
void
throw_Exception(const string &msg)
{
throw Exception(msg);
}
/***************************************************
* class Thing
*/
class Thing
{
public:
Thing();
void open();
static bool is_error(int) __attribute__((const));
static void check_code(int);
};
Thing::Thing() {}
inline bool
Thing::is_error(int code)
{
return (code >= 400) && (code <= 599);
}
void
Thing::check_code(int code)
{
if ( is_error(code) )
{
throw_Exception("crash!");
}
}
void
Thing::open()
{
check_code(530);
}
/************************************************************
* class AppObj
*/
class AppObj
{
private:
Thing m_thing;
public:
AppObj();
void open();
};
AppObj::AppObj()
: m_thing()
{}
void
AppObj::open()
{
m_thing.open();
}
/************************************************************
* main
*/
int
main()
{
try
{
AppObj app;
app.open();
}
catch(const Exception &e)
{
cout << "Caught application exception" << endl;
}
catch(...)
{
cout << "Caught unknown exception" << endl;
}
return 0;
}
More information about the Gcc-bugs
mailing list