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()); } };