Fix duplicateConditionalAssign FP (#4484)
* Fix #9406 FN redundant assignment of Boolean variable * Fix warning, refactor * Update testcondition.cpp * Fix duplicateConditionalAssign FP * Format
This commit is contained in:
parent
48999cf1d1
commit
3644d79162
|
@ -1764,10 +1764,13 @@ void CheckCondition::checkDuplicateConditionalAssign()
|
||||||
continue;
|
continue;
|
||||||
bool isRedundant = false;
|
bool isRedundant = false;
|
||||||
if (isBoolVar) {
|
if (isBoolVar) {
|
||||||
if (!astIsBool(condTok))
|
|
||||||
continue;
|
|
||||||
const bool isNegation = condTok->str() == "!";
|
const bool isNegation = condTok->str() == "!";
|
||||||
if (!(assignTok->astOperand1() && assignTok->astOperand1()->varId() == (isNegation ? condTok->next() : condTok)->varId()))
|
const Token* const varTok = isNegation ? condTok->next() : condTok;
|
||||||
|
const ValueType* vt = varTok->variable() ? varTok->variable()->valueType() : nullptr;
|
||||||
|
if (!(vt && vt->type == ValueType::Type::BOOL && !vt->pointer))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(assignTok->astOperand1() && assignTok->astOperand1()->varId() == varTok->varId()))
|
||||||
continue;
|
continue;
|
||||||
if (!(assignTok->astOperand2() && assignTok->astOperand2()->hasKnownIntValue()))
|
if (!(assignTok->astOperand2() && assignTok->astOperand2()->hasKnownIntValue()))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -5441,6 +5441,12 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(int& i) {\n"
|
||||||
|
" if (!i)\n"
|
||||||
|
" i = 1; \n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct S {\n" // #9406
|
check("struct S {\n" // #9406
|
||||||
" S() : b(false) {}\n"
|
" S() : b(false) {}\n"
|
||||||
" void f() {\n"
|
" void f() {\n"
|
||||||
|
|
Loading…
Reference in New Issue