Menu

odd new 1.74 warnings "Boolean result is used in bitwise operation. Clarify expression with parentheses"

2016-06-18
2016-12-20
  • Sean McBride

    Sean McBride - 2016-06-18

    I have a piece of code like this:

    int isUpperBound = ((j == 1) ^ (spacing[i] < 0));

    and cppcheck 1.74 started warning:

    "Boolean result is used in bitwise operation. Clarify expression with parentheses"

    What additional parens could I add? What is this warning trying to tell me really?

    Thanks,

    Sean

     
  • Mr. X

    Mr. X - 2016-06-18

    The check became too noisy, we know this and will fix it somehow for next release.

     
  • Sean McBride

    Sean McBride - 2016-08-13

    It seems unfixed in 1.75.

     
  • Daniel Marjamäki

    worksforme:

    daniel@raspberrypi:~/cppcheck $ ./cppcheck --enable=style ../a.c
    Checking ../a.c ...
    [../a.c:3]: (style) Variable 'isUpperBound' is assigned a value that is never used.
    daniel@raspberrypi:~/cppcheck $ ./cppcheck --version
    Cppcheck 1.75
    daniel@raspberrypi:~/cppcheck $ cat ../a.c
    
    void f() {
        int isUpperBound = ((j == 1) ^ (spacing[i] < 0));
    }
    
     
  • Sean McBride

    Sean McBride - 2016-12-19

    I've just revisited this in 1.76.1 and indeed it's basically fixed. I have only one case left:

    bool foundProperty = ...
    if (!foundProperty ^ (sliceOrder == 3))
    

    I can workaround it with:

    if ((!foundProperty) ^ (sliceOrder == 3))
    

    I guess it's debatable if this should be considered a false positive or not...

     
  • raynebc

    raynebc - 2016-12-20

    The warning seems completely applicable there.

     

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.