diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 4e9ddbc28..ed8af88c4 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1164,7 +1164,7 @@ void CheckCondition::alwaysTrueFalse() && !tok->isBoolean(); const bool constValExpr = Token::Match(tok, "%num%|%char%") && tok->astParent() && Token::Match(tok->astParent(),"&&|%oror%|?"); // just one number or char in boolean expression const bool compExpr = Token::Match(tok, "%comp%|!"); // a compare expression - + if (!(constIfWhileExpression || constValExpr || compExpr)) continue; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index ef78e3df7..e2ca1e2cb 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2207,9 +2207,9 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'a' is always true\n", errout.str()); check("void f() {\n" - " int a = 5;" - " while(a + 1) { a--; }\n" - "}"); + " int a = 5;" + " while(a + 1) { a--; }\n" + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n"