diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 89ed606bf..be39c0a24 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2323,6 +2323,11 @@ void CheckOther::comparisonOfTwoFuncsReturningBoolError(const Token *tok, const void CheckOther::checkComparisonOfBoolWithBool() { + // FIXME: This checking is "experimental" because of the false positives + // when self checking lib/tokenize.cpp (#2617) + if (!_settings->experimental) + return; + if (!_settings->isEnabled("style")) return; diff --git a/test/testother.cpp b/test/testother.cpp index 6eda51c8c..a1bb0048f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4080,29 +4080,32 @@ private: } void checkComparisonOfBoolWithBool() { - check("void f(){\n" - " int temp = 4;\n" - " bool b = compare2(6);\n" - " bool a = compare1(4);\n" - " if(b > a){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n" - "bool compare2(int temp){\n" - " if(temp == 5){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n"); + const char code[] = "void f(){\n" + " int temp = 4;\n" + " bool b = compare2(6);\n" + " bool a = compare1(4);\n" + " if(b > a){\n" + " printf(\"foo\");\n" + " }\n" + "}\n" + "bool compare1(int temp){\n" + " if(temp==4){\n" + " return true;\n" + " }\n" + " else\n" + " return false;\n" + "}\n" + "bool compare2(int temp){\n" + " if(temp == 5){\n" + " return true;\n" + " }\n" + " else\n" + " return false;\n" + "}\n"; + check(code, "test.cpp", true); ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + check(code, "test.cpp"); + ASSERT_EQUALS("", errout.str()); } void sizeofForNumericParameter() {