diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 82e509847..4d7f095c0 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1000,6 +1000,8 @@ void CheckCondition::alwaysTrueFalse() continue; if (!tok->hasKnownIntValue()) continue; + if (Token::Match(tok, "[01]")) + continue; // Don't warn in assertions. Condition is often 'always true' by intention. // If platform,defines,etc cause 'always false' then that is not dangerous neither. diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 33295a24f..ffc249ca1 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1810,7 +1810,7 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); - // #7750 warn about number and char literals in boolean expressions + // #7750 warn about char literals in boolean expressions check("void f() {\n" " if('a'){}\n" " if(L'b'){}\n" @@ -1819,7 +1819,6 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Condition ''a'' is always true\n" "[test.cpp:3]: (style) Condition ''b'' is always true\n" - "[test.cpp:4]: (style) Condition '1' is always true\n" "[test.cpp:4]: (style) Condition ''c'' is always true\n" "[test.cpp:5]: (style) Condition ''d'' is always true\n", errout.str()); }