Menu

Clang doesn't like the logic in lib/checkcondition.cpp

2023-08-25
2023-08-25
  • Andrew C Aitchison

    I get these warnings with clang++ v13 onwards. git blame suggests these are not new.

    clang++-16 -Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2 -pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar -g -std=gnu++0x -pipe -c -o lib/checkcondition.o lib/checkcondition.cpp
    lib/checkcondition.cpp:413:17: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
    if (tok && (diag(tok) | diag(tok->astParent())))
    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ||
    lib/checkcondition.cpp:413:17: note: cast one or both operands to int to silence this warning
    lib/checkcondition.cpp:507:9: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    if (diag(tok1) & diag(tok2))
    ^~~~~~~~~~~~~~~~~~~~~~~
    &&
    lib/checkcondition.cpp:507:9: note: cast one or both operands to int to silence this warning
    lib/checkcondition.cpp:569:9: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    if (diag(ifCond) & diag(elseIfCond))
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    &&
    lib/checkcondition.cpp:569:9: note: cast one or both operands to int to silence this warning
    lib/checkcondition.cpp:831:9: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    if (diag(tok1) & diag(tok2))
    ^~~~~~~~~~~~~~~~~~~~~~~
    &&
    lib/checkcondition.cpp:831:9: note: cast one or both operands to int to silence this warning
    lib/checkcondition.cpp:846:9: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    if (diag(tok1) & diag(tok2))
    ^~~~~~~~~~~~~~~~~~~~~~~
    &&
    lib/checkcondition.cpp:846:9: note: cast one or both operands to int to silence this warning
    lib/checkcondition.cpp:861:9: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    if (diag(cond1) & diag(cond2))
    ^~~~~~~~~~~~~~~~~~~~~~~~~
    &&
    lib/checkcondition.cpp:861:9: note: cast one or both operands to int to silence this warning
    6 warnings generated.

     
  • Daniel Marjamäki

    Spontanously I think that we sometimes do not want to short circuit. If you want to short circuit then use && and || otherwise use & and |.

    How do you build? With the normal Makefile? Maybe you somehow need to disable that warning.

     
    • Daniel Marjamäki

      In the code examples you show however.. it seems that a short circuit might make sense. The diag functions seems non-trivial.

       

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.