Menu

unreadVariable false positive on assignment through reference ?

xolodho
2021-11-12
2021-11-14
  • xolodho

    xolodho - 2021-11-12

    Hello. Just found a little issue. Take the following code snippet:

    void foo(int c[]) {
      int &cc = c[0];
      cc &= ~0xff;
    }
    

    then run cppcheck on that using --enable=all, this style warning appears:

    style: Variable 'cc' is assigned a value that is never used. [unreadVariable]
    int &cc = c[0];

    Here the assignment through the reference has actual use, so this seems like a false positive. Also, if using a pointer instead of a reference to get the same effect, then cppcheck doesn't complain.

    using cppcheck 2.6.

     
  • CHR

    CHR - 2021-11-14

    Thanks for reporting, Daniel has created a ticket here: https://trac.cppcheck.net/ticket/10597

     

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.