Fixed #7477 (False positive 'Assigned value is never used' in multithreaded context)

This commit is contained in:
Daniel Marjamäki 2016-09-03 20:38:36 +02:00
parent b97bdb5300
commit 60f22bd4ee
2 changed files with 21 additions and 0 deletions

View File

@ -1070,6 +1070,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
variables.use(tok->next()->varId(), tok); // use = read + write
} else if (Token::Match(tok, "[(,] %var% [,)]") && tok->previous()->str() != "*") {
variables.use(tok->next()->varId(), tok); // use = read + write
} else if (Token::Match(tok, "[(,] & %var% [,)]")) {
variables.eraseAll(tok->tokAt(2)->varId());
} else if (Token::Match(tok, "[(,] (") &&
Token::Match(tok->next()->link(), ") %var% [,)]")) {
variables.use(tok->next()->link()->next()->varId(), tok); // use = read + write
@ -1083,6 +1085,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
// function
else if (Token::Match(tok, "%var% (")) {
variables.read(tok->varId(), tok);
} else if (Token::Match(tok, "std :: ref ( %var% )")) {
variables.eraseAll(tok->tokAt(4)->varId());
}
else if (Token::Match(tok->previous(), "[{,] %var% [,}]")) {

View File

@ -161,6 +161,7 @@ private:
TEST_CASE(localvarAssignInWhile);
TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter
TEST_CASE(localvarFuncPtr); // #7194
TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
@ -3971,6 +3972,22 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarAddr() { // #7747
functionVariableUsage("void f() {\n"
" int x = 0;\n"
" dostuff(&x);\n"
" x = 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f() {\n"
" int x = 0;\n"
" dostuff(std::ref(x));\n"
" x = 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void chainedAssignment() {
// #5466
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"