Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug1509.cpp

1    #include <stdio.h>
2
3    class Person { public: ~Person(){} };
4    class Englishman :
5        public Person
6            { public: virtual ~Englishman(){ printf( "Goodbye\n" ); } };
7    class Japanese :
8        public Person
9            { public: virtual ~Japanese(){ printf( "Sayonara\n" ); } };
10   class German :
11       public Person
12           { public: virtual ~German(){ printf( "Auf Wiedersehen\n" ); } };
13
14   int main()
15       {
16       Person *p = new Japanese;
17       delete p;
18       p = new German;
19       delete p;
20       return 0;
21       }

The purpose of the exercise above is to show in principle how people of differing nationalities can give a farewell address in their native language. Unfortunately, the farewells are never given, and we even got a crash. What's going wrong?


bug1509.cpp lint Output

--- Module:   bug1509.cpp
                                       _
        { public: virtual ~Englishman(){ printf( "Goodbye\n" ); } };
bug1509.cpp(6) : Warning 1509: base class destructor for class 'Person' is not virtual
                                     _
        { public: virtual ~Japanese(){ printf( "Sayonara\n" ); } };
bug1509.cpp(9) : Warning 1509: base class destructor for class 'Person' is not virtual
                                   _
        { public: virtual ~German(){ printf( "Auf Wiedersehen\n" ); } };
bug1509.cpp(12) : Warning 1509: base class destructor for class 'Person' is not virtual

    --- Wrap-up for Module: bug1509.cpp

Info 753: local class 'Englishman' (line 4, file bug1509.cpp) not referenced

--- Global Wrap-up

Warning 1512: destructor for base class 'Person' (line 3, file bug1509.cpp) is not virtual

Reference Manual Explanation


1509  base class destructor for class 'Name' is not virtual  -- The indicated
      class is a base class for some derived class. It has a non-virtual destructor.
      Was this a mistake?  It is conventional to virtualize destructors of base
      classes so that it is safe to delete a base class pointer.   [19]

If you have comments or questions about this bug, please post them to our   Discussion Forum

Previous Bug - Bug #1559 - July 2005

[ new ] Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2006, Gimpel Software, All rights reserved.