Fix #11879 FN unreadVariable (regression) (#5345)

This commit is contained in:
chrchr-github 2023-08-21 10:44:17 +02:00 committed by GitHub
parent 725c431ecc
commit 3281fc91db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View File

@ -41,22 +41,22 @@ void CheckStatistics::addItem(const QString &tool, ShowTypes::ShowType type)
const QString lower = tool.toLower();
switch (type) {
case ShowTypes::ShowStyle:
::addItem(mStyle, tool);
::addItem(mStyle, lower);
break;
case ShowTypes::ShowWarnings:
::addItem(mWarning, tool);
::addItem(mWarning, lower);
break;
case ShowTypes::ShowPerformance:
::addItem(mPerformance, tool);
::addItem(mPerformance, lower);
break;
case ShowTypes::ShowPortability:
::addItem(mPortability, tool);
::addItem(mPortability, lower);
break;
case ShowTypes::ShowErrors:
::addItem(mError, tool);
::addItem(mError, lower);
break;
case ShowTypes::ShowInformation:
::addItem(mInformation, tool);
::addItem(mInformation, lower);
break;
case ShowTypes::ShowNone:
default:

View File

@ -1361,7 +1361,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
else if (!usage._var->isMaybeUnused() && !usage._modified && !usage._read && var) {
const Token* vnt = var->nameToken();
bool error = false;
if (vnt->next()->isSplittedVarDeclEq()) {
if (vnt->next()->isSplittedVarDeclEq() || (!var->isReference() && vnt->next()->str() == "=")) {
const Token* nextStmt = vnt->tokAt(2);
if (nextStmt->isExpandedMacro()) {
const Token* parent = nextStmt;

View File

@ -5689,9 +5689,8 @@ private:
"{\n"
" static int i = 0;\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n",
"",
errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -6305,6 +6304,15 @@ private:
" const ::std::lock_guard g(m);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f(const std::string& str, int i) {\n" // #11879
" const std::string s = str;\n"
" switch (i) {\n"
" default:\n"
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", errout.str());
}
void localVarClass() {