Reporting a Bug in exception handling involving multiple inheritance and templates - GCC 2.95.2
Hunter Moseley
hunter@cabm.rutgers.edu
Fri Dec 10 13:00:00 GMT 1999
This bug involves GCC 2.95.2ÃÂ on Redhat Linux 6.1 on a Pentium III-450
machine.
The following program produces an Abort core dump between printing "Test3"
and "Test4".
If this part is commented out, then a Segmentation Fault core dump
is produced after printing "Test4"
I used the following to compile:
ÃÂ ÃÂ ÃÂ % /usr/local/gcc-2.95.2/bin/c++ -static test1.cc
-o test1
Then I run it as follows:
ÃÂ
ÃÂ ÃÂ ÃÂ % test1
Here is the program "test1.cc":
-------------------------------------------------------
#include <iostream>
#include <exception>
#include <stdexcept>
#include <string>
ÃÂ
class AAException : public std::exception
ÃÂ {
ÃÂ public :
ÃÂ ÃÂ ÃÂ AAException();
ÃÂ ÃÂ ÃÂ AAException(const std::string& error_message);
ÃÂ ÃÂ ÃÂ AAException(const char* error_message);
ÃÂ ÃÂ ÃÂ virtual ~AAException();
ÃÂ };
template<class Exception, class Parent=AAException>
class AAExcept : public Parent, public Exception
ÃÂ {
ÃÂ public :
ÃÂ ÃÂ ÃÂ AAExcept()
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : Parent() {}
ÃÂ ÃÂ ÃÂ AAExcept(const std::string& error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : Parent(error_message) {};
ÃÂ ÃÂ ÃÂ AAExcept(const char* error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : Parent(error_message) {};
ÃÂ ÃÂ ÃÂ virtual ~AAExcept() {}
ÃÂ };
//
// Inlined AAException Member Functions
//
inline AAException::AAException()
ÃÂ {}
inline AAException::AAException(const std::string& error_message)
ÃÂ { }
inline AAException::AAException(const char* error_message)
ÃÂ { }
inline AAException::~AAException()
ÃÂ {}
// AAExcept<std::logic_error> specialization
template<>
class AAExcept<std::logic_error> : public AAException, public std::logic_error
ÃÂ {
ÃÂ public :
ÃÂ ÃÂ ÃÂ AAExcept()
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAException(), logic_error("") {}
ÃÂ ÃÂ ÃÂ AAExcept(const std::string& error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAException(error_message), logic_error("")
{};
ÃÂ ÃÂ ÃÂ AAExcept(const char* error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAException(error_message), logic_error("")
{};
ÃÂ ÃÂ ÃÂ virtual ~AAExcept() {}
ÃÂ };
// AAExcept<std::invalid_argument> specialization
template<>
class AAExcept<std::invalid_argument> : public AAExcept<std::logic_error>,
public std::invalid_argument
ÃÂ {
ÃÂ public :
ÃÂ ÃÂ ÃÂ AAExcept()
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAExcept<std::logic_error>(), invalid_argument("")
{}
ÃÂ ÃÂ ÃÂ AAExcept(const std::string& error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAExcept<std::logic_error>(error_message),
invalid_argument("") {};
ÃÂ ÃÂ ÃÂ AAExcept(const char* error_message)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ : AAExcept<std::logic_error>(error_message),
invalid_argument("") {};
ÃÂ ÃÂ ÃÂ virtual ~AAExcept() {}
ÃÂ };
ÃÂ
class A
ÃÂ { };
void main()
ÃÂ {
ÃÂ cout << "Test1" << endl;
ÃÂ try
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ throw AAExcept<A>("junk");
ÃÂ ÃÂ ÃÂ }
ÃÂ catch(A &e)
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ }
ÃÂ
ÃÂ cout << "Test2" << endl;
ÃÂ try
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ throw AAException("junk");
ÃÂ ÃÂ ÃÂ }
ÃÂ catch(std::exception &e)
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ }
ÃÂ
ÃÂ cout << "Test3" << endl;
ÃÂ try
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ throw AAExcept<std::logic_error>("junk");
ÃÂ ÃÂ ÃÂ }
ÃÂ catch(std::exception &e)
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ }
ÃÂ cout << "Test4" << endl;
ÃÂ try
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ throw AAExcept<std::invalid_argument>("junk");
ÃÂ ÃÂ ÃÂ }
ÃÂ catch(std::invalid_argument &e)
ÃÂ ÃÂ ÃÂ {
ÃÂ ÃÂ ÃÂ }
ÃÂ }
-------------------------------------------------
If there is a bug fix for this, I would love to know.
take care,
Hunter Moseley
--ÃÂ
Dr. Hunter Moseley --- CABM, Rutgers Univ.ÃÂ ÃÂ ÃÂ ÃÂ | hunter@cabm.rutgers.edu | (732) 235-5325
Not just a postdoc, but a fencer as well.ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ | Center for Advanced Biotechnology & Med.
ÃÂ My foil is sharp, but my tongue sharper still.| Rutgers University
ÃÂ So it's good that my foil is still sharp.ÃÂ ÃÂ ÃÂ | 679 Hoes Lane, Piscataway, NJ 08854-5638
ÃÂ
begin:vcard
n:Moseley;Hunter
tel;work:732-234-5361
x-mozilla-html:TRUE
org:Rutgers University;Center for Advanced Biotechnology and Medicine
adr:;;679 Hoes Lane;Piscataway;New Jersey;08854-5638;
version:2.1
email;internet:hunter@cabm.rutgers.edu
title:Post Doctoral Associate
note;quoted-printable:Extra Info: I am in the laboratory =0D=0Aof Dr. Gaetano T. Montelione
x-mozilla-cpt:;-15680
fn:Dr. Hunter Moseley
end:vcard
More information about the Gcc-bugs
mailing list