Fix #10505 FP unreadVariable for lock_guard variable (#3938)

This commit is contained in:
chrchr-github 2022-03-28 21:45:49 +02:00 committed by GitHub
parent 8bf8070923
commit 7b97230dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -1282,8 +1282,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
FwdAnalysis fwdAnalysis(mTokenizer->isCPP(), mSettings->library);
const Token* scopeEnd = getEndOfExprScope(expr, scope, /*smallest*/ false);
if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) {
if (!bailoutTypeName.empty() && bailoutTypeName != "auto") {
reportLibraryCfgError(tok, bailoutTypeName);
if (!bailoutTypeName.empty()) {
if (bailoutTypeName != "auto")
reportLibraryCfgError(tok, bailoutTypeName);
continue;
}

View File

@ -3676,9 +3676,9 @@ void stdbind()
// TODO cppcheck-suppress ignoredReturnValue #9369
std::bind(stdbind_helper, 1);
// cppcheck-suppress unreadVariable
// TODO cppcheck-suppress unreadVariable
auto f1 = std::bind(stdbind_helper, _1);
// cppcheck-suppress unreadVariable
// TODO cppcheck-suppress unreadVariable
auto f2 = std::bind(stdbind_helper, 10);
}

View File

@ -3241,6 +3241,12 @@ private:
" auto&& g = std::lock_guard<std::mutex> { mutex };\n"
"}\n");
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Variable 'g' is assigned a value that is never used.\n", errout.str());
functionVariableUsage("void f() {\n"
" auto a = RAII();\n"
" auto b { RAII() };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvar47() { // #6603
@ -5808,10 +5814,13 @@ private:
" auto r = std::pair<std::string, std::string>(\"a\", \"b\");\n"
" auto s = std::pair<std::string, std::string>{ \"a\", \"b\" };\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used.\n"
"[test.cpp:3]: (style) Variable 'q' is assigned a value that is never used.\n"
"[test.cpp:4]: (style) Variable 'r' is assigned a value that is never used.\n"
"[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used.\n"
"[test.cpp:3]: (style) Variable 'q' is assigned a value that is never used.\n"
"[test.cpp:4]: (style) Variable 'r' is assigned a value that is never used.\n"
"[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n",
"[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used.\n"
"[test.cpp:3]: (style) Variable 'q' is assigned a value that is never used.\n",
errout.str());
}
void localVarClass() {