Fixed #7369 (False positive knownConditionTrueFalse - assertions)

This commit is contained in:
Daniel Marjamäki 2016-02-06 14:37:44 +01:00
parent b3a0d418e6
commit 7bd034c009
2 changed files with 14 additions and 0 deletions

View File

@ -981,6 +981,12 @@ void CheckCondition::alwaysTrueFalse()
if (!tok->astParent() || !Token::Match(tok->astParent()->previous(), "%name% ("))
continue;
// Don't warn in assertions. Condition is often 'always true' by intention.
// If platform,defines,etc cause 'always false' then that is not dangerous neither.
const std::string &str = tok->astParent()->previous()->str();
if (str.find("assert")!=std::string::npos || str.find("ASSERT")!=std::string::npos)
continue;
// Don't warn when there are expanded macros..
bool isExpandedMacro = false;
std::stack<const Token*> tokens;

View File

@ -1614,6 +1614,14 @@ private:
" if ($x != $0) {}\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"
" int x = 0;\n"
" assert(x == 0);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkInvalidTestForOverflow() {