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]

C++: Instantiation of abstract classes possible


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


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