From 7b97230dd2f752aec902ec45764126f61576715b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 28 Mar 2022 21:45:49 +0200 Subject: [PATCH] Fix #10505 FP unreadVariable for lock_guard variable (#3938) --- lib/checkunusedvar.cpp | 5 +++-- test/cfg/std.cpp | 4 ++-- test/testunusedvar.cpp | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index c6f5e0f4c..659235246 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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; } diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index bca35fd38..cff83ed30 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -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); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 5c8910e79..02eaf6af3 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3241,6 +3241,12 @@ private: " auto&& g = std::lock_guard { 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(\"a\", \"b\");\n" " auto s = std::pair{ \"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() {