Fix #11545 FP unreadVariable with std::span (#4792)

This commit is contained in:
chrchr-github 2023-02-14 06:11:24 +01:00 committed by GitHub
parent ef49dff488
commit 4f8329b2df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -482,6 +482,8 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const
return false; return false;
if (hasVolatileCastOrVar(expr)) if (hasVolatileCastOrVar(expr))
return false; return false;
if (Token::simpleMatch(expr, "[") && astIsContainerView(expr->astOperand1()))
return false;
mWhat = What::UnusedValue; mWhat = What::UnusedValue;
Result result = check(expr, startToken, endToken); Result result = check(expr, startToken, endToken);
return (result.type == FwdAnalysis::Result::Type::NONE || result.type == FwdAnalysis::Result::Type::RETURN) && !possiblyAliased(expr, startToken); return (result.type == FwdAnalysis::Result::Type::NONE || result.type == FwdAnalysis::Result::Type::RETURN) && !possiblyAliased(expr, startToken);

View File

@ -6000,6 +6000,11 @@ private:
"[test.cpp:2]: (style) Variable 'p' 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", "[test.cpp:3]: (style) Variable 'q' is assigned a value that is never used.\n",
errout.str()); errout.str());
functionVariableUsage("void f(std::span<int> s) {\n" // #11545
" s[0] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void localVarClass() { void localVarClass() {