File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1288,6 +1288,11 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage()
12881288 while (Token::Match (op1tok, " .|[|*" ))
12891289 op1tok = op1tok->astOperand1 ();
12901290
1291+ // Bail out for overloaded indexing
1292+ if (op1tok && op1tok->valueType () && op1tok->valueType ()->pointer == 0 &&
1293+ op1tok->valueType ()->type == ValueType::Type::RECORD && Token::simpleMatch (op1tok->astParent (), " [" ))
1294+ continue ;
1295+
12911296 // Assignment in macro => do not warn
12921297 if (isAssignment && tok->isExpandedMacro () && op1tok && op1tok->isExpandedMacro ())
12931298 continue ;
Original file line number Diff line number Diff line change @@ -225,6 +225,7 @@ class TestUnusedVar : public TestFixture {
225225 TEST_CASE (localvarStruct13); // #10398
226226 TEST_CASE (localvarStruct14);
227227 TEST_CASE (localvarStructArray);
228+ TEST_CASE (localvarOverloadedSubscript);
228229 TEST_CASE (localvarUnion1);
229230
230231 TEST_CASE (localvarOp); // Usage with arithmetic operators
@@ -5666,6 +5667,16 @@ class TestUnusedVar : public TestFixture {
56665667 ASSERT_EQUALS (" [test.cpp:3:12]: (style) Variable 'x[0].a' is assigned a value that is never used. [unreadVariable]\n " , errout_str ());
56675668 }
56685669
5670+ void localvarOverloadedSubscript () {
5671+ functionVariableUsage (" struct A { B &operator [](size_t i); }\n "
5672+ " struct B { int x; };\n "
5673+ " void f(B *b) {\n "
5674+ " A a(b);\n "
5675+ " a[0].b = 0;\n "
5676+ " }\n " );
5677+ ASSERT_EQUALS (" " , errout_str ());
5678+ }
5679+
56695680 void localvarUnion1 () {
56705681 // #9707
56715682 functionVariableUsage (" static short read(FILE *fp) {\n "
You can’t perform that action at this time.
0 commit comments