File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1466,6 +1466,20 @@ void CheckOther::checkConstVariable()
14661466 if (changeStructData)
14671467 continue ;
14681468 }
1469+ // Calling non-const method using non-const reference
1470+ if (var->isReference ()) {
1471+ bool callNonConstMethod = false ;
1472+ for (const Token* tok = var->nameToken (); tok != scope->bodyEnd && tok != nullptr ; tok = tok->next ()) {
1473+ if (tok->variable () == var && Token::Match (tok, " %var% . * ( & %name% ::" )) {
1474+ const Token *ftok = tok->linkAt (3 )->previous ();
1475+ if (!ftok->function () || !ftok->function ()->isConst ())
1476+ callNonConstMethod = true ;
1477+ break ;
1478+ }
1479+ }
1480+ if (callNonConstMethod)
1481+ continue ;
1482+ }
14691483
14701484 constVariableError (var, function);
14711485 }
Original file line number Diff line number Diff line change @@ -2615,6 +2615,10 @@ class TestOther : public TestFixture {
26152615 " panels.erase(it);\n "
26162616 " }" );
26172617 ASSERT_EQUALS (" " , errout.str ());
2618+
2619+ check (" struct S { void f(); int i; };\n "
2620+ " void call_f(S& s) { (s.*(&S::f))(); }\n " );
2621+ ASSERT_EQUALS (" " , errout.str ());
26182622 }
26192623
26202624 void constParameterCallback () {
You can’t perform that action at this time.
0 commit comments