Menu

[false positive] style: struct member is never used. [unusedStructMember] when member is only used in offsetof()

2024-10-18
2024-11-27
  • Yann Droneaud

    Yann Droneaud - 2024-10-18

    Hi,

    cppcheck is reporting struct member as unused despite it being used in
    offsetof():

    #include <stddef.h>
    
    struct foobar {
       char unused;
    };
    
    size_t offset_unused = offsetof(struct foobar, unused);
    

    cppcheck reports

    struct-offsetof.c:4:8: style: struct member 'foobar::unused' is never used. [unusedStructMember]
      char unused;
           ^

    offsetof() macro is part of the language since C89 I believe.

    Is it possible to extend cppcheck so that it has some knowledge of the
    macro without parsing <stddef.h> ?</stddef.h>

    Regards.

     
  • Yann Droneaud

    Yann Droneaud - 2024-11-24

    Hi,

    I thought this was worth a bug report and it was the proper channel for it to be recorded in https://trac.cppcheck.net/ as I don't have an account there.

    Is it possible to open a bug for this issue ?

    Regards.

     
  • CHR

    CHR - 2024-11-25

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/13345

     
    ❤️
    1
  • Yann Droneaud

    Yann Droneaud - 2024-11-27

    And it's already fixed ( https://github.com/danmar/cppcheck/pull/7041 ). Thanks a lot !

     

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.