Fixed #3410 (Comparing bool against bool produces false positive)
This commit is contained in:
parent
6dc2a6e7ab
commit
f8181df340
|
@ -1530,7 +1530,7 @@ void CheckOther::checkComparisonOfBoolWithInt()
|
|||
if (iVar != boolvars.end() && !iVar->second) { // Variable has to be of non-boolean standard type
|
||||
comparisonOfBoolWithIntError(varTok, constTok->str());
|
||||
}
|
||||
} else if (Token::Match(tok, "%var% >|>=|==|!=|<=|< %var%")) { // Comparing two variables, one of them boolean, one of them integer
|
||||
} else if (Token::Match(tok, "%var% >|>=|==|!=|<=|< %var%") && !Token::Match(tok->tokAt(3), ".|::|(")) { // Comparing two variables, one of them boolean, one of them integer
|
||||
const Token *var1Tok = tok->tokAt(2);
|
||||
const Token *var2Tok = tok;
|
||||
std::map<unsigned int, bool>::const_iterator iVar1 = boolvars.find(var1Tok->varId());
|
||||
|
|
|
@ -138,6 +138,7 @@ private:
|
|||
TEST_CASE(comparisonOfBoolWithInt3);
|
||||
TEST_CASE(comparisonOfBoolWithInt4);
|
||||
TEST_CASE(comparisonOfBoolWithInt5);
|
||||
TEST_CASE(comparisonOfBoolWithInt6);
|
||||
|
||||
TEST_CASE(duplicateIf);
|
||||
TEST_CASE(duplicateBranch);
|
||||
|
@ -3711,6 +3712,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolWithInt6() {
|
||||
check("void SetVisible(int index, bool visible) {\n"
|
||||
" bool (SciTEBase::*ischarforsel)(char ch);\n"
|
||||
" if (visible != GetVisible(index)) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void duplicateIf() {
|
||||
check("void f(int a, int &b) {\n"
|
||||
" if (a) { b = 1; }\n"
|
||||
|
|
Loading…
Reference in New Issue