Click on image to see enlargment

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

            bug616.cpp

1    #include <stdio.h>
2    enum spring_thing
3        { bird, flower, baseball, golf };
4    void print_sound( enum spring_thing x )
5        {
6        switch (x)
7            {
8        case bird:
9            printf( "chirp chirp" );
10       case flower:
11           printf( "mum's the word" );
12       case baseball:
13           printf( "play ball" );
14       case golf:
15           printf( "$#*?&" );
16       default:  return;
17           }
18       printf( "\n" );
19       }
20   int main()
21       {
22       print_sound( bird );
23       print_sound( flower );
24       print_sound( baseball );
25       print_sound( golf );
26       return 0;
27       }

This C/C++ program is an attempt to portray the beautiful sounds of spring but instead we obtain a cacophony. What went wrong?


bug616.cpp lint Output

--- Module:   bug616.cpp (C++)
    _
    case flower:
bug616.cpp(10) : Warning 616: control flows into case/default
bug616.cpp(10) : Info 825: control flows into case/default without -fallthrough
    comment
    _
    case baseball:
bug616.cpp(12) : Warning 616: control flows into case/default
bug616.cpp(12) : Info 825: control flows into case/default without -fallthrough
    comment
    _
    case golf:
bug616.cpp(14) : Warning 616: control flows into case/default
bug616.cpp(14) : Info 825: control flows into case/default without -fallthrough
    comment
    _
    default:  return;
bug616.cpp(16) : Warning 616: control flows into case/default
bug616.cpp(16) : Info 825: control flows into case/default without -fallthrough
    comment
                 _
    printf( "\n" );
bug616.cpp(18) : Warning 527: Unreachable code at token 'printf'

Reference Manual Explanation


616    control flows into case/default  -- It is possible for flow of
       control to fall into a case statement or a default statement from
       above.  Was this deliberate or did the programmer forget to
       insert a break statement?  If this was deliberate then place a
       comment immediately before the statement that was flagged as in:

               case 'a':  a = 0;
                  /* fall through */
               case 'b':  a++;

       Note that the message will not be given for a case that merely
       follows another case without an intervening statement.  Also,
       there must actually be a possibility for flow to occur from
       above.


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


Previous Bug - Bug #866 - March 2010

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.