Fixed #8978 (False positive: Variable assigned value that is never used when assigning via iterator)
This commit is contained in:
parent
e0fe8fa2cd
commit
5654630099
|
@ -1185,16 +1185,25 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
op1tok = op1tok->astOperand1();
|
||||
|
||||
const Variable *op1Var = op1tok ? op1tok->variable() : nullptr;
|
||||
if (op1Var && op1Var->isReference() && op1Var->nameToken() != tok->astOperand1())
|
||||
// todo: check references
|
||||
continue;
|
||||
if (op1Var) {
|
||||
if (op1Var->isReference() && op1Var->nameToken() != tok->astOperand1())
|
||||
// todo: check references
|
||||
continue;
|
||||
|
||||
if (op1Var && op1Var->isStatic())
|
||||
// todo: check static variables
|
||||
continue;
|
||||
if (op1Var->isStatic())
|
||||
// todo: check static variables
|
||||
continue;
|
||||
|
||||
if (op1Var && op1Var->nameToken()->isAttributeUnused())
|
||||
continue;
|
||||
if (op1Var->nameToken()->isAttributeUnused())
|
||||
continue;
|
||||
|
||||
// Bailout for unknown template classes, we have no idea what side effects such assignments have
|
||||
if (mTokenizer->isCPP() &&
|
||||
op1Var->isClass() &&
|
||||
(!op1Var->valueType() || op1Var->valueType()->type == ValueType::Type::UNKNOWN_TYPE) &&
|
||||
Token::findsimplematch(op1Var->typeStartToken(), "<", op1Var->typeEndToken()))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is there a redundant assignment?
|
||||
const Token *start = tok->findExpressionStartEndTokens().second->next();
|
||||
|
|
|
@ -201,6 +201,7 @@ private:
|
|||
TEST_CASE(bracesInitCpp11);// #7895 - "int var{123}" initialization
|
||||
|
||||
TEST_CASE(argument);
|
||||
TEST_CASE(argumentClass);
|
||||
TEST_CASE(escapeAlias); // #9150
|
||||
}
|
||||
|
||||
|
@ -4578,6 +4579,14 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'foo.x' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void argumentClass() {
|
||||
functionVariableUsage(
|
||||
"void foo(std::insert_iterator<C> it) {\n"
|
||||
" it = 123;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void escapeAlias() {
|
||||
functionVariableUsage(
|
||||
"struct A {\n"
|
||||
|
|
Loading…
Reference in New Issue