Fixed #6968 (unusedPrivateFunction not correct, called by inner class)

This commit is contained in:
Daniel Marjamäki 2016-05-16 20:52:50 +02:00
parent 7fffc09b17
commit 99fc13ee70
2 changed files with 15 additions and 4 deletions

View File

@ -899,10 +899,10 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)
return true;
}
for (std::list<Scope*>::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) {
if ((*i)->isClassOrStruct())
if (checkFunctionUsage(privfunc, *i)) // Check nested classes, which can access private functions of their base
return true;
for (std::list<Type*>::const_iterator i = scope->definedTypes.begin(); i != scope->definedTypes.end(); ++i) {
const Type *type = *i;
if (type->enclosingScope == scope && checkFunctionUsage(privfunc, type->classScope))
return true;
}
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {

View File

@ -392,6 +392,17 @@ private:
" };\n"
"};");
ASSERT_EQUALS("", errout.str());
check("class A {\n" // #6968 - outer definition
"public:\n"
" class B;\n"
"private:\n"
" void f() {}\n"
"}\n"
"class A::B {"
" B() { A a; a.f(); }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}