I would like to suggest a new test for CppCheck - to flag if a function that returns a 'bool' is compared against an integer instead of true/false. Consider the following:
std::strings;...if(s.compare("abc")==0)...
This code works great. I then updated my code to use "contains" instead of compare, but in doing so I forgot to remove the " == 0"
std::strings;...if(s.contains("abc")==0)...
I have now flipped the logic and broken my code. But a CppCheck test for bool tested against an integer would flag this issue in my code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to suggest a new test for CppCheck - to flag if a function that returns a 'bool' is compared against an integer instead of true/false. Consider the following:
This code works great. I then updated my code to use "contains" instead of compare, but in doing so I forgot to remove the " == 0"
I have now flipped the logic and broken my code. But a CppCheck test for bool tested against an integer would flag this issue in my code.
This is caught by clang-tidy's readability-implicit-bool-conversion.