Click on image to see enlargment

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

            bug1539.cpp

1    #include <stdio.h>
2    struct Batter
3        {
4        int at_bats; int hits;
5        const Batter& operator=( const Batter& rhs )
6            {
7            if( this == &rhs ) return *this;
8            at_bats = rhs.at_bats;
9            return *this;
10           }
11       double ave() { return (double) hits / at_bats; }
12       };
13
14   int main()
15       {
16       Batter Foxx, Ruth={120,50};
17       Foxx = Ruth;
18       printf( "Ruth is hitting %g\n", Ruth.ave() );
19       printf( "Foxx is hitting %g\n", Foxx.ave() );
20       return 0;
21       }

Our programmer felt that the assignment of the Ruth batting statistics to Foxx would have meant that their averages should be the same and was astounded to find a substantial difference. Where did he go wrong?


bug1539.cpp lint Output

--- Module:   bug1539.cpp (C++)
        _
        }
bug1539.cpp(10) : Warning 1539: member 'Batter::hits' (line 4) not assigned by assignment operator
bug1539.cpp(4) : Info 830: Location cited in prior message
                                                   _
    double ave() { return (double) hits / at_bats; }
bug1539.cpp(11) : Info 1762: Member function 'Batter::ave(void)' could be made const

Reference Manual Explanation


1539   member 'Symbol' (Location) not assigned by assignment operator 
       -- The indicated Symbol was not assigned by an assignment
       operator.  Was this an oversight?  It is not strictly necessary
       to initialize all members in an assignment operator because the
       'this' class is presumably already initialized.  But it is easy
       to overlook the assignment of individual members.  It is also
       easy to overlook your responsibility to assign base class
       members.  This is not done for you automatically. [12, Item 16]

       The message is not given for const members or reference members.
       If you have a member that is deliberately not initialized you may
       suppress the message for that member only using -esym.

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

Previous Bug - Bug #419 - April 2006

[ 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.