Fixed #7890 (1.77 false positive from knownConditionTrueFalse with function-like macros)

This commit is contained in:
Daniel Marjamäki 2017-03-03 19:53:16 +01:00
parent b1ce229006
commit 1c6c209353
2 changed files with 9 additions and 3 deletions

View File

@ -998,9 +998,7 @@ void CheckCondition::alwaysTrueFalse()
continue; continue;
if (tok->link()) // don't write false positives when templates are used if (tok->link()) // don't write false positives when templates are used
continue; continue;
if (tok->values.size() != 1U) if (!tok->hasKnownIntValue())
continue;
if (!tok->values.front().isKnown())
continue; 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.
@ -1033,6 +1031,9 @@ void CheckCondition::alwaysTrueFalse()
break; break;
} }
} }
for (const Token *parent = tok; parent; parent = parent->astParent()) {
isExpandedMacro |= parent->isExpandedMacro();
}
if (isExpandedMacro) if (isExpandedMacro)
continue; continue;

View File

@ -1783,6 +1783,11 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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. // 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 // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither
check("void f() {\n" check("void f() {\n"