Also, I have just about every warning enabled for MSVC, gcc, and clang. None of these compilers have complained about the arithmetic being ambiguous. Are you sure this cppcheck linting rule is not a false report?
Last edit: mcandre 2021-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the question is if human programmers can misread the code.
I guess (pair[1] & 64 ? 55 : 48) is pretty clear.. it would be strange if the intention would be that the condition was 64.. so I guess we can prevent the warning in this case (when last operand in condition is a integer literal).
Last edit: Daniel Marjamäki 2021-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's a stylistic message. If you are sure that nobody will misunderstand such code ever in your team then you can safely suppress it.
For information , we check debian source code continuously. And we get such warnings here and there. At least in Debian, I have the feeling that there are quite often real mistakes found by this warning.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
cppcheck complains that a bitwise-and in the conditional part of my ternary is ambiguous (clarifyCalculation).
https://github.com/mcandre/swiper/blob/master/src/swiper.cpp#L31
However, C++ Reference says that the precedence order is unambiguous:
https://en.cppreference.com/w/cpp/language/operator_precedence
Also, I have just about every warning enabled for MSVC, gcc, and clang. None of these compilers have complained about the arithmetic being ambiguous. Are you sure this cppcheck linting rule is not a false report?
Last edit: mcandre 2021-04-17
it is 100% clear in the standard.
the question is if human programmers can misread the code.
I guess
(pair[1] & 64 ? 55 : 48)
is pretty clear.. it would be strange if the intention would be that the condition was64
.. so I guess we can prevent the warning in this case (when last operand in condition is a integer literal).Last edit: Daniel Marjamäki 2021-04-17
It's a stylistic message. If you are sure that nobody will misunderstand such code ever in your team then you can safely suppress it.
For information , we check debian source code continuously. And we get such warnings here and there. At least in Debian, I have the feeling that there are quite often real mistakes found by this warning.