Menu

"unsigned short const int" is not parsed right

2021-06-04
2021-06-06
  • Siim Ainsaar

    Siim Ainsaar - 2021-06-04

    I created the following file and named it "t.c":

    unsigned short f(void)
    {
        unsigned short const int x = 1;
        return x;
    }
    

    Then I ran the following command with cppcheck 2.4.1:

    cppcheck t.c --enable=style --debug
    

    The result claims wrongly that x is not assigned to:

    Checking t.c ...
    
    
    ##file t.c
    1: unsigned short f ( )
    2: {
    3: const unsigned short x@var1 ; int x@var1 1 ;
    4: return x@var1 ;
    5: }
    
    
    
    ##Value flow
    Line 3
      1 always 1
    t.c:3:30: style: Variable 'x' is not assigned a value. [unassignedVariable]
        unsigned short const int x = 1;
                                 ^
    

    When I move "const" to any other place in the declaration, the warning disappears.

     
  • Daniel Marjamäki

    Thanks! I can reproduce. That looks strange.

     
  • Daniel Marjamäki

    Fixed by 3c3435dd10943668a9d323f5b5b33f995f9e9d4b

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.