known conditions: dont warn about 0 or 1 conditions as those look intentional

This commit is contained in:
Daniel Marjamäki 2017-03-08 18:39:19 +01:00
parent 0073a633b0
commit 263c3596d5
2 changed files with 3 additions and 2 deletions

View File

@ -1000,6 +1000,8 @@ void CheckCondition::alwaysTrueFalse()
continue; continue;
if (!tok->hasKnownIntValue()) if (!tok->hasKnownIntValue())
continue; continue;
if (Token::Match(tok, "[01]"))
continue;
// Don't warn in assertions. Condition is often 'always true' by intention. // 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. // If platform,defines,etc cause 'always false' then that is not dangerous neither.

View File

@ -1810,7 +1810,7 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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" check("void f() {\n"
" if('a'){}\n" " if('a'){}\n"
" if(L'b'){}\n" " if(L'b'){}\n"
@ -1819,7 +1819,6 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (style) Condition ''a'' is always true\n" ASSERT_EQUALS("[test.cpp:2]: (style) Condition ''a'' is always true\n"
"[test.cpp:3]: (style) Condition ''b'' 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:4]: (style) Condition ''c'' is always true\n"
"[test.cpp:5]: (style) Condition ''d'' is always true\n", errout.str()); "[test.cpp:5]: (style) Condition ''d'' is always true\n", errout.str());
} }