diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 7409252c6..b9d0c8290 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -998,9 +998,7 @@ void CheckCondition::alwaysTrueFalse() continue; if (tok->link()) // don't write false positives when templates are used continue; - if (tok->values.size() != 1U) - continue; - if (!tok->values.front().isKnown()) + if (!tok->hasKnownIntValue()) continue; // Don't warn in assertions. Condition is often 'always true' by intention. @@ -1033,6 +1031,9 @@ void CheckCondition::alwaysTrueFalse() break; } } + for (const Token *parent = tok; parent; parent = parent->astParent()) { + isExpandedMacro |= parent->isExpandedMacro(); + } if (isExpandedMacro) continue; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 8be72eaa3..33295a24f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1783,6 +1783,11 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " $if $( 1 $&& $x()) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // Don't warn in assertions. Condition is often 'always true' by intention. // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither check("void f() {\n"