Fixed #3454 (false positive: (style) Variable 'iFaktor' is assigned a value that is never used)
This commit is contained in:
parent
65b58bcb99
commit
2ae48c7aef
|
@ -662,20 +662,17 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "%type% const| *|&| const| *| const| %var% ;|[|,|)|=|(") && tok->str() != "return" && tok->str() != "throw") { // Declaration: Skip
|
if (Token::Match(tok, "%type% const| *|&| const| *| const| %var% [;=[(]") && tok->str() != "return" && tok->str() != "throw") { // Declaration: Skip
|
||||||
const Token* old = tok;
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
while (Token::Match(tok, "const|*|&"))
|
while (Token::Match(tok, "const|*|&"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
tok = Token::findmatch(tok, "[,;)=(]");
|
tok = Token::findmatch(tok, "[;=[(]");
|
||||||
if (tok && Token::Match(tok, "( %var% )")) // Simple initialization through copy ctor
|
if (tok && Token::Match(tok, "( %var% )")) // Simple initialization through copy ctor
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
else if (tok && Token::Match(tok, "= %var% ;")) // Simple initialization
|
else if (tok && Token::Match(tok, "= %var% ;")) // Simple initialization
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (!tok)
|
if (!tok)
|
||||||
break;
|
break;
|
||||||
if (tok->str() == ")" && tok->link() && Token::Match(tok->link()->previous(), "if|for|while"))
|
|
||||||
tok = old;
|
|
||||||
}
|
}
|
||||||
// Freeing memory (not considered "using" the pointer if it was also allocated in this function)
|
// Freeing memory (not considered "using" the pointer if it was also allocated in this function)
|
||||||
if (Token::Match(tok, "free|g_free|kfree|vfree ( %var% )") ||
|
if (Token::Match(tok, "free|g_free|kfree|vfree ( %var% )") ||
|
||||||
|
|
|
@ -84,6 +84,7 @@ private:
|
||||||
TEST_CASE(localvar36); // ticket #2805
|
TEST_CASE(localvar36); // ticket #2805
|
||||||
TEST_CASE(localvar37); // ticket #3078
|
TEST_CASE(localvar37); // ticket #3078
|
||||||
TEST_CASE(localvar38);
|
TEST_CASE(localvar38);
|
||||||
|
TEST_CASE(localvar39); // ticket #3454
|
||||||
TEST_CASE(localvaralias1);
|
TEST_CASE(localvaralias1);
|
||||||
TEST_CASE(localvaralias2); // ticket #1637
|
TEST_CASE(localvaralias2); // ticket #1637
|
||||||
TEST_CASE(localvaralias3); // ticket #1639
|
TEST_CASE(localvaralias3); // ticket #1639
|
||||||
|
@ -1371,6 +1372,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvar39() {
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" int a = 1;\n"
|
||||||
|
" foo(x*a);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void localvaralias1() {
|
void localvaralias1() {
|
||||||
functionVariableUsage("void foo()\n"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue