Click on image to see enlargment

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

            bug1568.cpp

1    //lint -e641 -e655 allow bit-wise operators on compatible enums
2    //lint -u  unit checkout
3
4    enum tea { cinnamon=1, ginseng=2, ginger=4,
5         goji=8, anise=0x10, licorice=0x20, kava=0x40,
6         clover=0x80, hawthorn=0x100, tulsi=0x200 };
7    typedef int Blend;
8    Blend StdMix(void), StdTaste(void), StdSpice(void);
9
10   Blend WakeUp = ginger | ginseng;
11   Blend SleepDown = kava | clover;
12   Blend Throaty = StdMix() | licorice;
13   Blend TasteGood = StdSpice() | kava;
14   Blend Spicy = cinnamon | anise;
15
16   Blend StdMix() { return StdTaste() | hawthorn; }
17   Blend StdTaste() { return TasteGood | goji; }
18   Blend StdSpice() { return cinnamon | anise; }

Elaine is opening up a tea shoppe with a wonderful assortment of herbal teas. The code shown initializes a number of tea blends according to her recipes but something is going wrong. Throaty doesn't seem to have enough cinnamon.


bug1568.cpp lint Output

--- Module:   bug1568.cpp (C++)

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

Info 749: local enumeration constant 'tea::tulsi' (line 6, file bug1568.cpp) not referenced

Warning 1568: Variable 'Throaty' (line 12, file bug1568.cpp) accesses variable 'TasteGood'
    before the latter is initialized through calls: 'StdMix() => StdTaste()' 

Reference Manual Explanation


1568   Variable 'Symbol' (Location) accesses variable 'Symbol' before the latter is
       initialized through calls: 'String'  -- A variable was dynamically initialized using
       an expression that contained a call to a function and that function referenced a
       variable that was also dynamically initialized but later in the module.  For example:

                 int g(void);
                 int f(void);
                 int x = f();
                 int y = g();
                 int f() { return y; }

       The initialization of both x and y are dynamic.  The order of dynamic initialization
       within a module is in the order in which the initialization is specified.  Thus when
       the call is made upon function f() to initialize x, variable y will not yet have been
       initialized.


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


Previous Bug - Bug #530 - April 2011

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