Click on image to see enlargment

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

            bug774.cpp

1    #include <stdio.h>
2
3    enum Spirits { rum, gin, scotch };
4    enum Mixer { coke, vermouth, water, tonic };
5
6    bool ok( Spirits s, Mixer m )
7        {
8        if( s == rum && m != coke ) return false;
9        if( s == gin && (m != vermouth ||
10           m != tonic) )  return false;
11       if( s == scotch && m != water ) return false;
12       return true;
13       }
14
15   int main()
16       {
17       if( !ok( rum, coke ) ||
18           !ok( gin, vermouth ) ||
19           !ok( scotch, water ) )
20           printf( "The drink checker is broken\n" );
21       return 0;
22       }

For this New Year's Eve, Bartender Bill is automating his drink preparations, making sure, among other things, that the drinks are prepared with the usual conventions of good taste. However the program keeps reporting that the compatibility test is 'broken'. What's going wrong?


bug774.cpp lint Output

--- Module:   bug774.cpp (C++)
                    _
        m != tonic) )  return false;
bug774.cpp(10) : Info 774: Boolean within 'right side of && within if' always
    evaluates to True [Reference: file bug774.cpp: lines 9, 10]

Reference Manual Explanation


774    Boolean within 'String' always evaluates to [True/False]  -- The
       indicated clause (String is one of if, while or for (2nd
       expression)) has an argument that appears to always evaluate to
       either 'True' or 'False' (as indicated in the message).
       Information is gleaned from a variety of sources including prior
       assignment statements and initializers.  Compare this with
       message 506 which is based on testing constants or combinations
       of constants.  Also compare with the Elective Note 944 which can
       sometimes provide more detailed information.


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


Previous Bug - Bug #687 - December 2009

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 2010, Gimpel Software, All rights reserved.