Fixed #8797 (exprDependsOnThis handle method call in non-inline method)

This commit is contained in:
Daniel Marjamäki 2018-10-24 20:17:00 +02:00
parent 2348dcde6c
commit b8e8b12783
2 changed files with 19 additions and 2 deletions

View File

@ -180,9 +180,12 @@ static bool exprDependsOnThis(const Token *expr)
// calling nonstatic method?
if (Token::Match(expr->previous(), "!!:: %name% (") && expr->function() && expr->function()->nestedIn && expr->function()->nestedIn->isClassOrStruct()) {
// is it a method of this?
const Scope *nestedIn = expr->scope();
while (nestedIn && nestedIn != expr->function()->nestedIn)
const Scope *nestedIn = expr->scope()->functionOf;
if (nestedIn && nestedIn->function)
nestedIn = nestedIn->function->token->scope();
while (nestedIn && nestedIn != expr->function()->nestedIn) {
nestedIn = nestedIn->nestedIn;
}
return nestedIn == expr->function()->nestedIn;
}
return exprDependsOnThis(expr->astOperand1()) || exprDependsOnThis(expr->astOperand2());

View File

@ -2037,6 +2037,20 @@ private:
" int get() const;\n"
"};");
ASSERT_EQUALS("", errout.str());
check("class C {\n"
"public:\n"
" bool f() const { return x > 0; }\n"
" void g();\n"
" int x = 0;\n"
"};\n"
"\n"
"void C::g() {\n"
" bool b = f();\n"
" x += 1;\n"
" if (!b && f()) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void identicalInnerCondition() {