From 263c3596d545002b5300fc512c1a680514284105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Mar 2017 18:39:19 +0100 Subject: [PATCH] known conditions: dont warn about 0 or 1 conditions as those look intentional --- lib/checkcondition.cpp | 2 ++ test/testcondition.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) 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()); }