Fixed #5619 (false positive: unusedVariable - array accessed by pointer variable only)
This commit is contained in:
parent
7161daefbd
commit
ac85b78e2a
|
@ -594,9 +594,16 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
|
||||||
} else { // not a local variable (or an unsupported local variable)
|
} else { // not a local variable (or an unsupported local variable)
|
||||||
if (var1->_type == Variables::pointer && !dereference) {
|
if (var1->_type == Variables::pointer && !dereference) {
|
||||||
// check if variable declaration is in this scope
|
// check if variable declaration is in this scope
|
||||||
if (var1->_var->scope() == scope)
|
if (var1->_var->scope() == scope) {
|
||||||
|
// If variable is used in RHS then "use" variable
|
||||||
|
for (const Token *rhs = tok; rhs && rhs->str() != ";"; rhs = rhs->next()) {
|
||||||
|
if (rhs->varId() == varid1) {
|
||||||
|
variables.use(varid1, tok);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
variables.clearAliases(varid1);
|
variables.clearAliases(varid1);
|
||||||
else {
|
} else {
|
||||||
// no other assignment in this scope
|
// no other assignment in this scope
|
||||||
if (var1->_assignments.find(scope) == var1->_assignments.end()) {
|
if (var1->_assignments.find(scope) == var1->_assignments.end()) {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -116,6 +116,7 @@ private:
|
||||||
TEST_CASE(localvaralias11); // ticket #4423 - iterator
|
TEST_CASE(localvaralias11); // ticket #4423 - iterator
|
||||||
TEST_CASE(localvaralias12); // ticket #4394
|
TEST_CASE(localvaralias12); // ticket #4394
|
||||||
TEST_CASE(localvaralias13); // ticket #4487
|
TEST_CASE(localvaralias13); // ticket #4487
|
||||||
|
TEST_CASE(localvaralias14); // ticket #5619
|
||||||
TEST_CASE(localvarasm);
|
TEST_CASE(localvarasm);
|
||||||
TEST_CASE(localvarstatic);
|
TEST_CASE(localvarstatic);
|
||||||
TEST_CASE(localvarextern);
|
TEST_CASE(localvarextern);
|
||||||
|
@ -3008,6 +3009,14 @@ private:
|
||||||
TODO_ASSERT_EQUALS("a is assigned value that is never used", "", errout.str());
|
TODO_ASSERT_EQUALS("a is assigned value that is never used", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvaralias14() { // #5619
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" char a[4], *p=a;\n"
|
||||||
|
" p = dostuff(p);\n"
|
||||||
|
"}");
|
||||||
|
TODO_ASSERT_EQUALS("p is assigned a value that is never used", "", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void localvarasm() {
|
void localvarasm() {
|
||||||
functionVariableUsage("void foo(int &b)\n"
|
functionVariableUsage("void foo(int &b)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue