Fixed #6315 (false positive - unreadVariable - variable is used via pointer)
This commit is contained in:
parent
3d7265309b
commit
0a03bbb320
|
@ -770,8 +770,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
doAssignment(variables, i->nameToken(), false, scope);
|
doAssignment(variables, i->nameToken(), false, scope);
|
||||||
} else {
|
} else {
|
||||||
// could be "var = {...}" OR "var{...}" (since C++11)
|
// could be "var = {...}" OR "var{...}" (since C++11)
|
||||||
const Token* tokBraceStart = NULL;
|
const Token* tokBraceStart = nullptr;
|
||||||
if (defValTok->str() == "=" && defValTok->next()->str() == "{") {
|
if (Token::simpleMatch(defValTok, "= {")) {
|
||||||
// "var = {...}"
|
// "var = {...}"
|
||||||
tokBraceStart = defValTok->next();
|
tokBraceStart = defValTok->next();
|
||||||
} else if (defValTok->str() == "{") {
|
} else if (defValTok->str() == "{") {
|
||||||
|
@ -902,6 +902,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (!var->isReference())
|
if (!var->isReference())
|
||||||
variables.read(tok->varId(), tok);
|
variables.read(tok->varId(), tok);
|
||||||
|
} else if (tok->str() == "[" && Token::simpleMatch(skipBrackets(tok),"= {")) {
|
||||||
|
const Token * const rhs1 = skipBrackets(tok)->next();
|
||||||
|
for (const Token *rhs = rhs1->link(); rhs != rhs1; rhs = rhs->previous()) {
|
||||||
|
if (rhs->varId())
|
||||||
|
variables.readAll(rhs->varId(), rhs);
|
||||||
|
}
|
||||||
} else if (var->typeEndToken()->str() == ">") // Be careful with types like std::vector
|
} else if (var->typeEndToken()->str() == ">") // Be careful with types like std::vector
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -117,6 +117,7 @@ private:
|
||||||
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(localvaralias14); // ticket #5619
|
||||||
|
TEST_CASE(localvaralias15); // ticket #6315
|
||||||
TEST_CASE(localvarasm);
|
TEST_CASE(localvarasm);
|
||||||
TEST_CASE(localvarstatic);
|
TEST_CASE(localvarstatic);
|
||||||
TEST_CASE(localvarextern);
|
TEST_CASE(localvarextern);
|
||||||
|
@ -3017,6 +3018,16 @@ private:
|
||||||
TODO_ASSERT_EQUALS("p is assigned a value that is never used", "", errout.str());
|
TODO_ASSERT_EQUALS("p is assigned a value that is never used", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvaralias15() { // #6315
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" int x=3;\n"
|
||||||
|
" int *p = &x;\n"
|
||||||
|
" int *p2[1] = {p};\n"
|
||||||
|
" dostuff(p2);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", 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