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;
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;

View File

@ -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"