Menu

False positive unusedStructMember in header file

Dan George
2021-11-16
2021-11-16
  • Dan George

    Dan George - 2021-11-16

    ```
    dan@danuc:~/sandbox/cppcheck$ cat unusedStructMember.h

    typedef struct foobar_s
    {
        int foo;
        int bar;
    } foobar_t;
    

    dan@danuc:~/sandbox/cppcheck$ cppcheck --enable=style --language=c unusedStructMember.h
    Checking unusedStructMember.h ...
    unusedStructMember.h:4:9: style: struct member 'foobar_s::foo' is never used. [unusedStructMember]
    int foo;
    ^
    unusedStructMember.h:5:9: style: struct member 'foobar_s::bar' is never used. [unusedStructMember]
    int bar;
    ^
    dan@danuc:~/sandbox/cppcheck$ cppcheck --version
    Cppcheck 2.7 dev
    dan@danuc:~/sandbox/cppcheck$ git -C ~/tools/cppcheck/ describe
    1.40-21987-g2998382c8```

     
  • Daniel Marjamäki

    This is by intention. If you check a header directly you will get this FP. The handling of ifdefs does not work very well neither when you check the header directly..
    check the c/c++ files that include the header instead.

     
    • Daniel Marjamäki

      if you really want to check headers directly anyway.. you can do it. but I suggest that you suppress this warning then.

       
      • Dan George

        Dan George - 2021-11-16

        Ah, okay. I'm using cppcheck with vim ale plugin. I've a PR to change how the plugin handles header files: https://github.com/dense-analysis/ale/pull/3983

         

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.