This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Reporting a Bug in exception handling involving multiple inheritance and templates - GCC 2.95.2


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]