From 120f3072ebe39074f698fb288c6717ccb76af4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 29 Jul 2015 12:51:00 +0200 Subject: [PATCH] alwaysTrueFalse: Dont write warning when comparison is made in macro --- lib/checkcondition.cpp | 2 ++ test/testcondition.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 6f876704d..0c9dcd1d1 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -977,6 +977,8 @@ void CheckCondition::alwaysTrueFalse() continue; if (!tok->values.front().isKnown()) continue; + if (tok->isExpandedMacro()) + continue; if (tok->astParent() && Token::Match(tok->astParent()->previous(), "%name% (")) alwaysTrueFalseError(tok, tok->values.front().intvalue != 0); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 81c7956e6..70f3eb8b8 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1510,6 +1510,14 @@ private: " if (!x) {}\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition !x is always true\n", errout.str()); + + // Avoid FP when condition comes from macro + check("void f() {\n" + " int x = 0;\n" + " if (a) { return; }\n" // <- this is just here to fool simplifyKnownVariabels + " if ($!x) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };