Fix #11923 FN unreadVariable (regression) (#5409)

This commit is contained in:
chrchr-github 2023-09-11 11:36:03 +02:00 committed by GitHub
parent 639a4131c4
commit aa281501c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -498,7 +498,7 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const
bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) const
{
if (expr->isUnaryOp("*"))
if (expr->isUnaryOp("*") && !expr->astOperand1()->isUnaryOp("&"))
return true;
const bool macro = false;
@ -540,7 +540,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
continue;
for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) {
if (isSameExpression(mCpp, macro, subexpr, addrOf, mLibrary, pure, followVar))
if (subexpr != addrOf && isSameExpression(mCpp, macro, subexpr, addrOf, mLibrary, pure, followVar))
return true;
}
}

View File

@ -2641,11 +2641,11 @@ private:
"}");
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable '*(b+i)' is assigned a value that is never used.\n", "", errout.str());
functionVariableUsage("void f() {\n" // #11832
functionVariableUsage("void f() {\n" // #11832, #11923
" int b;\n"
" *(&b) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable '*(&b)' is assigned a value that is never used.\n", errout.str());
}
void localvar8() {