Avoid 'Condition always true/false' FP when part of the condition is an expanded macro
This commit is contained in:
parent
c5673612e2
commit
1752c4f4f0
|
@ -25,6 +25,7 @@
|
|||
#include "symboldatabase.h"
|
||||
|
||||
#include <limits>
|
||||
#include <stack>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -977,11 +978,29 @@ void CheckCondition::alwaysTrueFalse()
|
|||
continue;
|
||||
if (!tok->values.front().isKnown())
|
||||
continue;
|
||||
if (tok->isExpandedMacro())
|
||||
if (!tok->astParent() || !Token::Match(tok->astParent()->previous(), "%name% ("))
|
||||
continue;
|
||||
|
||||
if (tok->astParent() && Token::Match(tok->astParent()->previous(), "%name% ("))
|
||||
alwaysTrueFalseError(tok, tok->values.front().intvalue != 0);
|
||||
// Don't warn when there are expanded macros..
|
||||
bool isExpandedMacro = false;
|
||||
std::stack<const Token*> tokens;
|
||||
tokens.push(tok);
|
||||
while (!tokens.empty()) {
|
||||
const Token *tok2 = tokens.top();
|
||||
tokens.pop();
|
||||
if (!tok2)
|
||||
continue;
|
||||
tokens.push(tok2->astOperand1());
|
||||
tokens.push(tok2->astOperand2());
|
||||
if (tok2->isExpandedMacro()) {
|
||||
isExpandedMacro = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isExpandedMacro)
|
||||
continue;
|
||||
|
||||
alwaysTrueFalseError(tok, tok->values.front().intvalue != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -935,10 +935,10 @@ private:
|
|||
|
||||
void incorrectLogicOperator9() { // #6069 "False positive incorrectLogicOperator due to dynamic_cast"
|
||||
check("class MyType;\n"
|
||||
"class OtherType;\n"
|
||||
"void foo (OtherType* obj) { \n"
|
||||
" assert((!obj) || dynamic_cast<MyType*>(obj));\n"
|
||||
"}");
|
||||
"class OtherType;\n"
|
||||
"void foo (OtherType* obj) { \n"
|
||||
" assert((!obj) || dynamic_cast<MyType*>(obj));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -1528,6 +1528,13 @@ private:
|
|||
" if ($!x) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" if (a) { return; }\n" // <- this is just here to fool simplifyKnownVariabels
|
||||
" if ($x != $0) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue