alwaysTrueFalse: Dont write warning when comparison is made in macro

This commit is contained in:
Daniel Marjamäki 2015-07-29 12:51:00 +02:00
parent fc25ed8c86
commit 120f3072eb
2 changed files with 10 additions and 0 deletions

View File

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

View File

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