alwaysTrueFalse: Dont write warning when comparison is made in macro
This commit is contained in:
parent
fc25ed8c86
commit
120f3072eb
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue