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,17 +1185,26 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||||||
op1tok = op1tok->astOperand1();
|
op1tok = op1tok->astOperand1();
|
||||||
|
|
||||||
const Variable *op1Var = op1tok ? op1tok->variable() : nullptr;
|
const Variable *op1Var = op1tok ? op1tok->variable() : nullptr;
|
||||||
if (op1Var && op1Var->isReference() && op1Var->nameToken() != tok->astOperand1())
|
if (op1Var) {
|
||||||
|
if (op1Var->isReference() && op1Var->nameToken() != tok->astOperand1())
|
||||||
// todo: check references
|
// todo: check references
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (op1Var && op1Var->isStatic())
|
if (op1Var->isStatic())
|
||||||
// todo: check static variables
|
// todo: check static variables
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (op1Var && op1Var->nameToken()->isAttributeUnused())
|
if (op1Var->nameToken()->isAttributeUnused())
|
||||||
continue;
|
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?
|
// Is there a redundant assignment?
|
||||||
const Token *start = tok->findExpressionStartEndTokens().second->next();
|
const Token *start = tok->findExpressionStartEndTokens().second->next();
|
||||||
|
|
||||||
|
@ -201,6 +201,7 @@ private:
|
|||||||
TEST_CASE(bracesInitCpp11);// #7895 - "int var{123}" initialization
|
TEST_CASE(bracesInitCpp11);// #7895 - "int var{123}" initialization
|
||||||
|
|
||||||
TEST_CASE(argument);
|
TEST_CASE(argument);
|
||||||
|
TEST_CASE(argumentClass);
|
||||||
TEST_CASE(escapeAlias); // #9150
|
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());
|
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() {
|
void escapeAlias() {
|
||||||
functionVariableUsage(
|
functionVariableUsage(
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user