Fixed #9759 (False positive: constParameter on parameter used by non-const call via pointer to member function)
This commit is contained in:
parent
cdc34fe92f
commit
c7ef602cd6
|
@ -1466,6 +1466,20 @@ void CheckOther::checkConstVariable()
|
||||||
if (changeStructData)
|
if (changeStructData)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Calling non-const method using non-const reference
|
||||||
|
if (var->isReference()) {
|
||||||
|
bool callNonConstMethod = false;
|
||||||
|
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next()) {
|
||||||
|
if (tok->variable() == var && Token::Match(tok, "%var% . * ( & %name% ::")) {
|
||||||
|
const Token *ftok = tok->linkAt(3)->previous();
|
||||||
|
if (!ftok->function() || !ftok->function()->isConst())
|
||||||
|
callNonConstMethod = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (callNonConstMethod)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
constVariableError(var, function);
|
constVariableError(var, function);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2615,6 +2615,10 @@ private:
|
||||||
" panels.erase(it);\n"
|
" panels.erase(it);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct S { void f(); int i; };\n"
|
||||||
|
"void call_f(S& s) { (s.*(&S::f))(); }\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void constParameterCallback() {
|
void constParameterCallback() {
|
||||||
|
|
Loading…
Reference in New Issue