Menu

cppcheck 1.71 false union member not used

2016-02-04
2016-02-04
  • Wilson Snyder

    Wilson Snyder - 2016-02-04

    The following small test case extracted from a larger program with cppcheck 1.71 (but not 1.52) gives

    $ cppcheck --enable=all below.cpp

    [...:4]: (style) union member 'Anonymous0::r' is never used.
    

    It is being set, and read through the other member. I can appreciate some use of unions is for two disjoint but non-simultanious data sets in which case not using one would be an error, but perhaps if you see a union with two members, one being written and the other read, you could auto suppress it?

    #include <stdint.h>
    extern uint64_t r_to_u(double r);
    uint64_t r_to_u(double r) {
        union { double r; uint64_t ld; } u;
        u.r = r;
        return u.ld;
    }
    
     
  • Alexander Mai

    Alexander Mai - 2016-02-04

    If you can reproduce it with the latest version still (1.72) you should report it on http://trac.cppcheck.net !

     

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.