Troubles with exception specification

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Tue Sep 22 05:33:00 GMT 1998


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




More information about the Gcc mailing list