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]

Troubles with exception specification



There are 2 problems with the exception specification in egcs-1.1.

1. In the sample below, the virtual function D::func,
that overrides the virtual function B::func, 
has a less restrictive exception specification.
However the compiler does compile the sample without any warning!

2. The call of B::func should throw `bad_exception', but it doesn't!

On Linux (RedHat 5.1, PC) it causes:
Aborted (core dumped),

on Linux (S.u.S.E. 5.1, PC, libc 5)
IOT trap/Abort.


//////////
// main.cc
//////////

# include <iostream.h>
# include <stdexcept>

class B {
  public:
    virtual ~B() throw() {}
    virtual void func() throw(logic_error, bad_exception)
    {throw runtime_error("XXL");}
};

class D : public B {
  public:
    virtual void func() {}
};

int main()
{
  try {
     B b;
     b.func();
  }
  catch (exception& exc) {
     cerr << exc.what() << '\n';
  }
}


Ryszard Kabatek
---
Martin-Luther University Halle-Wittenberg
Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129



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