egcs 1.1.2 allows throwing an ABC

Jukka Suomela
Sun Apr 25 03:45:00 GMT 1999

Dear Sirs,

AFAIK C++ doesn't allow throwing an instance of an abstract base class.
However, egcs-1.1.2 allows it.

I believe this is a bug. (However, if it for some strange reason is a
feature, I'd like to see at least a compiler switch to disallow this thing.)



  gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

A sample code:

  class A {
    virtual int f() = 0;

  int main(void) {
    try {
      throw A();
    catch (A& a) {
    return 0;

Commands used to compile the code:

  I've tried both of these, the same results:

    g++ -ansi -pedantic -Wall -W  

  Linux kernel 2.2.5

egcs configuration:

  ./configure --prefix=/someplace --enable-shared
  make bootstrap
  make install

What I got:

  No errors, no warnings. It silently compiled and linked the program.

What I expected:

  An error telling I can't instantiate an abstract class with pure virtual


It never complained anything. No errors, no warnings. It compiled and linked
successfully. (Of course I got a runtime error "pure virtual method called"
if I tried to run the binary.)

The same occured in a completely different, larger project - egcs disallows
me to instantiate an ABC but I still can throw it.

A few other people tried the same code on their egcs-1.1.2 and they got the
same results. One person tryid his egcs-1.1.1 and reported that it compiled
successfully, too.

Many other compilers (including g++ 2.7.x.x, BCB3, Digital cxx and
egcs-1.0.3a-14) gave a proper error message.

Best regards,

 Jukka Suomela -
 Servin-Maijan tie 10 F 83, 02150 ESPOO, FINLAND

More information about the Gcc-bugs mailing list