When all warnings are enabled the g++ compiler should warn when a virtual method is called in a constructor or destructor for the class containing the virtual method.
Steps: 1. Compile the following using the command: g++ -g -Wall -ansi -pedantic -c #include <iostream> class Base { public: Base() { Method(); } virtual ~Base() {} protected: virtual void Method() { std::cout << "Base method.\n"; } }; class Derived : public Base { public: Derived() { Method(); } protected: void Method() { std::cout << "Derived method.\n"; } }; Results: The code compiles with no errors or warnings Expected: The call to Method in the Derived constructor will call Base::Method, and not Derived::Method because Derived is not constructed and available for use yet. The compiler should warn about these kinds of virtual methods calls in constructors as the program may not yield the kind of results the developer is expecting. -- Summary: g++ should warn about virtual methods called in constructors and destructors Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tron dot thomas at verizon dot net CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24058