This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++: Instantiation of abstract classes possible
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: C++: Instantiation of abstract classes possible
- From: Klaas Teschauer <klaas at kite dot rhein-main dot de>
- Date: Sat, 10 Jul 1999 23:27:08 +0200
Description
C++ allows it to create unnamend temporary objects via a direct call
to a constructor, as if part of of a new construct. When using this to
instantiate an abstract class, egcs fails to spot that the class is
abstract.
class Test
{
public:
virtual int f() = 0;
};
void func( Test& t ) { t.f(); }
int main() { func( Test() ); }
Compiling and running this gives the following results:
kite:~/project/egcs-bugs/pure_func$ g++ -g -Wall pure_func.cc
pure_func.cc: In function `int main()':
pure_func.cc:9: warning: initialization of non-const reference `class Test &' from rvalue `Test'
pure_func.cc:7: warning: in passing argument 1 of `func(Test &)'
kite:~/project/egcs-bugs/pure_func$ ./a.out
pure virtual method called
kite:~/project/egcs-bugs/pure_func$
Environment
Operating system: Debian Linux 2.1 (slink) on Intel i386 architecture,
Kernel version 2.0.36, output of g++ --version: egcs-2.91.0. The
compiler was installed as part of the Debian system and not modified
in any way.
Klaas Teschauer