Menu

False positive with bool bitwise OR

2020-10-29
2020-10-30
  • Nikita Leontiev

    Nikita Leontiev - 2020-10-29

    Since cppcheck 2.0 false positive occurs with bool bitwise OR:

    #include <inttypes.h>
    #include <stdio.h>
    
    int main()
    {
        bool f1 = true, f2 = false, f3 = true;
        uint32_t num = (f3 << 2) | (f2 << 1) | f1;
        printf("%#x\n", num);
        return 0;
    }
    
    test.cpp:7:42: style:inconclusive: Boolean expression 'f1' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]
        uint32_t num = (f3 << 2) | (f2 << 1) | f1;
                                             ^
    
     
  • Daniel Marjamäki

    I believe this is by intention. Some people wants that bool variables are treated specially and not used in arithmetic ways. I think it's inspired by Java. Obviously you do not want to have such special handling. Please suppress this warning.

     

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.