Skip to content

Commit 4f8329b

Browse files
Fix #11545 FP unreadVariable with std::span (#4792)
1 parent ef49dff commit 4f8329b

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/fwdanalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const
482482
return false;
483483
if (hasVolatileCastOrVar(expr))
484484
return false;
485+
if (Token::simpleMatch(expr, "[") && astIsContainerView(expr->astOperand1()))
486+
return false;
485487
mWhat = What::UnusedValue;
486488
Result result = check(expr, startToken, endToken);
487489
return (result.type == FwdAnalysis::Result::Type::NONE || result.type == FwdAnalysis::Result::Type::RETURN) && !possiblyAliased(expr, startToken);

test/testunusedvar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6000,6 +6000,11 @@ class TestUnusedVar : public TestFixture {
60006000
"[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used.\n"
60016001
"[test.cpp:3]: (style) Variable 'q' is assigned a value that is never used.\n",
60026002
errout.str());
6003+
6004+
functionVariableUsage("void f(std::span<int> s) {\n" // #11545
6005+
" s[0] = 0;\n"
6006+
"}\n");
6007+
ASSERT_EQUALS("", errout.str());
60036008
}
60046009

60056010
void localVarClass() {

0 commit comments

Comments
 (0)