Click on image to see enlargment

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

            bug1559.cpp

1    class Flag
2        {
3        int nerrors;        // number of errors
4        int nstars;         // number of stars
5      public:
6        Flag() : nerrors(0), nstars(0) {}
7        ~Flag()
8            {
9            try { if( nerrors > 0 ) throw "error state"; }
10           catch( char * const &s ) { }
11           }
12       void addstar( int n ) { nstars += n; if(!n) nerrors++; }
13       };
14
15   void flag_history()
16       {
17       Flag flag;
18       flag.addstar(48);
19       flag.addstar(2);
20       flag.addstar(0);
21       }

The above is a hollowed out version of a program that is intended to compute an arrangement of stars for the American flag. But there is a serious flaw. Can you spot it?


bug1559.cpp lint Output

--- Module:   bug1559.cpp
                                 _
        catch( char * const &s ) { }
bug1559.cpp  10  Info 1775: catch block does not catch any declared exception
bug1559.cpp  10  Info 715: Symbol 's' (line 10) not referenced
        _
        }
bug1559.cpp  11  Warning 1559: Uncaught exception 'const char *' may be thrown
    in destructor 'Flag::~Flag(void)'

--- Global Wrap-up

Info 714: Symbol 'flag_history(void)' (line 15, file bug1559.cpp) not
    referenced

Reference Manual Explanation


1559  Uncaught exception 'Name' may be thrown in destructor 'Symbol'  -- The named
      exception occurred within a try block and was either not caught by any handler
      or was caught but then thrown from the handler.  Destructors should normally
      not throw exceptions [23, Item 11].

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

Previous Bug - Bug #719 - June 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.