egcs 1.1.2 allows throwing an ABC
Jukka Suomela
jukka@narnia.tky.hut.fi
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.)
------
Compiler:
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
A sample code:
class A {
public:
virtual int f() = 0;
};
int main(void) {
try {
throw A();
}
catch (A& a) {
a.f();
}
return 0;
}
Commands used to compile the code:
I've tried both of these, the same results:
g++ example.cc
g++ -ansi -pedantic -Wall -W example.cc
System:
i686-pc-linux-gnu
Linux kernel 2.2.5
glibc-2.0.7pre6
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
methods.
------
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 - http://narnia.tky.hut.fi
Servin-Maijan tie 10 F 83, 02150 ESPOO, FINLAND
More information about the Gcc-bugs
mailing list