Skip to content

Commit 2c5bf92

Browse files
Fix #14769 FP unreadVariable with address in chained assignment of unused variable (#8926)
1 parent 6fc12c3 commit 2c5bf92

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎lib/checkunusedvar.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c
10091009
const Token * const equal = skipBracketsAndMembers(tok->next());
10101010

10111011
// checked for chained assignments
1012-
if (tok != start && equal && equal->str() == "=") {
1012+
if (tok != start && (Token::simpleMatch(equal, "=") || (start->astParent() && Token::simpleMatch(start->astParent()->astParent(), "=")))) {
10131013
const nonneg int varId = tok->varId();
10141014
const Variables::VariableUsage * const var = variables.find(varId);
10151015

‎test/testunusedvar.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,14 @@ class TestUnusedVar : public TestFixture {
33703370
" return a;\n"
33713371
"}\n");
33723372
ASSERT_EQUALS("[test.cpp:5:14]: (style) Variable 'b[c]' is assigned a value that is never used. [unreadVariable]\n", errout_str());
3373+
3374+
functionVariableUsage("int f() {\n" // #14769
3375+
" int i = 2;\n"
3376+
" const int *a, *c;\n"
3377+
" a = c = &i;\n"
3378+
" return *a;\n"
3379+
"}\n");
3380+
ASSERT_EQUALS("[test.cpp:4:11]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\n", errout_str());
33733381
}
33743382

33753383
void localvar24() { // ticket #1803

0 commit comments

Comments
 (0)