From f8181df340809a9e802e69950d35226cac239d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 20 Dec 2011 06:38:05 +0100 Subject: [PATCH] Fixed #3410 (Comparing bool against bool produces false positive) --- lib/checkother.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 9076a28b5..955153986 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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::const_iterator iVar1 = boolvars.find(var1Tok->varId()); diff --git a/test/testother.cpp b/test/testother.cpp index 26bbc76bc..f95a5c5fb 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"